Les posteurs les plus actifs de la semaine
Aucun utilisateur |
Sujets les plus vus
Matrice de corrélation avec NA...
2 participants
Page 1 sur 1
Matrice de corrélation avec NA...
Bonjour à tous,
J'ai un soucis avec une matrice de corrélation qui m'affiche "NA" quasiment partout (Image en PJ). J'imagine que c'est parceque les variables en questions contiennent des NA ?
J'ai pourtant essayé avec ce code :
cor(mydata[,c("Chcig","Chalc","Chfru","Chspo","Chsel","Age","Tps")], use="complete obs")
Mais j'ai ce message d'erreur :
Error in cor(mydata[, c("Chcig", "Chalc", "Chfru", "Chspo", "Chsel", "Age", :
argument 'use' incorrect
En vous remerciant de votre aide
J'ai un soucis avec une matrice de corrélation qui m'affiche "NA" quasiment partout (Image en PJ). J'imagine que c'est parceque les variables en questions contiennent des NA ?
J'ai pourtant essayé avec ce code :
cor(mydata[,c("Chcig","Chalc","Chfru","Chspo","Chsel","Age","Tps")], use="complete obs")
Mais j'ai ce message d'erreur :
Error in cor(mydata[, c("Chcig", "Chalc", "Chfru", "Chspo", "Chsel", "Age", :
argument 'use' incorrect
En vous remerciant de votre aide
- Fichiers joints
LILOUFB- Nombre de messages : 14
Date d'inscription : 30/12/2016
Re: Matrice de corrélation avec NA...
Etes-vous sûr(e) que vos données sont numériques ? Je soupçonne par exemple que les décimales sont représentées avec des virgules, plutôt que des points. Pouvez-vous poster la sortie de summary(mydata) ?
HTH, Eric.
HTH, Eric.
Eric Wajnberg- Nombre de messages : 1238
Date d'inscription : 14/09/2012
Re: Matrice de corrélation avec NA...
Bonjour,
La voici :
> summary(mydata)
NA. AV.cig AV.alc AV.fru AV.spo
Min. : 1 Min. :1.000 Min. :1.000 Min. :2.000 Min. :1.000
1st Qu.:12 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:3.000 1st Qu.:1.000
Median :23 Median :4.000 Median :3.000 Median :4.000 Median :3.000
Mean :23 Mean :3.545 Mean :2.977 Mean :3.733 Mean :2.733
3rd Qu.:34 3rd Qu.:5.000 3rd Qu.:3.250 3rd Qu.:4.000 3rd Qu.:4.000
Max. :45 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
NA's :1 NA's :1
AV.sel AC.1 AC.2 AC.3 AC.4
Min. :1.000 Min. :1.000 Min. :1.0 Min. :1.000 Min. :1.000
1st Qu.:1.000 1st Qu.:3.750 1st Qu.:2.0 1st Qu.:1.000 1st Qu.:2.000
Median :1.000 Median :4.000 Median :4.0 Median :1.000 Median :3.000
Mean :1.841 Mean :4.023 Mean :3.2 Mean :1.311 Mean :2.956
3rd Qu.:3.000 3rd Qu.:5.000 3rd Qu.:5.0 3rd Qu.:1.000 3rd Qu.:4.000
Max. :5.000 Max. :5.000 Max. :5.0 Max. :4.000 Max. :5.000
NA's :1 NA's :1
AC.5 AC.6 AC.7 AC.8 AC.9
Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.0
1st Qu.:2.000 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:1.000 1st Qu.:1.0
Median :3.000 Median :2.000 Median :3.000 Median :2.000 Median :3.0
Mean :2.711 Mean :2.511 Mean :3.267 Mean :2.186 Mean :2.6
3rd Qu.:4.000 3rd Qu.:3.000 3rd Qu.:4.000 3rd Qu.:3.000 3rd Qu.:4.0
Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.0
NA's :2
AC.10 AC.11 AC.12 AC.13 AC.14
Min. :1.000 Min. :1.000 Min. :1.0 Min. :1.000 Min. :1.000
1st Qu.:2.000 1st Qu.:2.000 1st Qu.:2.0 1st Qu.:1.000 1st Qu.:1.000
Median :3.000 Median :4.000 Median :3.5 Median :2.000 Median :4.000
Mean :3.067 Mean :3.068 Mean :3.0 Mean :2.311 Mean :2.978
3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:4.0 3rd Qu.:3.000 3rd Qu.:4.000
Max. :5.000 Max. :5.000 Max. :5.0 Max. :5.000 Max. :5.000
NA's :1 NA's :1
AC.15 AC.16 AC.17 AP.cig AP.alc
Min. :1.000 Min. :1.000 Min. :1.000 Min. :3.000 Min. :1.000
1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:5.000 1st Qu.:3.000
Median :1.000 Median :2.000 Median :2.000 Median :5.000 Median :3.000
Mean :1.578 Mean :2.318 Mean :2.159 Mean :4.932 Mean :3.465
3rd Qu.:2.000 3rd Qu.:3.250 3rd Qu.:3.000 3rd Qu.:5.000 3rd Qu.:4.000
Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
NA's :1 NA's :1 NA's :1 NA's :2
AP.fru AP.spo AP.sel Sexe Age SSR
Min. :2.000 Min. :1.000 Min. :1.000 F:10 Min. :33.00 Non: 6
1st Qu.:4.000 1st Qu.:3.750 1st Qu.:1.000 H:35 1st Qu.:54.00 Oui:39
Median :4.000 Median :4.000 Median :3.000 Median :58.00
Mean :4.159 Mean :4.045 Mean :2.721 Mean :59.78
3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:4.000 3rd Qu.:69.00
Max. :5.000 Max. :5.000 Max. :5.000 Max. :82.00
NA's :1 NA's :1 NA's :2
Tps Diab Obes Hyper Autres Lieu Chcig
Min. : 1.00 Non:40 Non:43 Non:34 Non:35 CA : 6 Min. :0.000
1st Qu.: 1.00 Oui: 5 Oui: 2 Oui:11 Oui:10 HL :36 1st Qu.:0.000
Median : 2.00 MDM: 3 Median :1.000
Mean : 39.09 Mean :1.419
3rd Qu.: 8.00 3rd Qu.:3.000
Max. :336.00 Max. :4.000
NA's :2
Chalc Chfru Chspo Chsel Score.c
Min. :0.0000 Min. :0.0000 Min. :0.000 Min. :0.000 Min. : 4.00
1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.000 1st Qu.:0.000 1st Qu.: 8.00
Median :0.0000 Median :0.0000 Median :1.000 Median :1.000 Median :12.00
Mean :0.5714 Mean :0.4545 Mean :1.386 Mean :0.907 Mean :11.51
3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:2.250 3rd Qu.:1.000 3rd Qu.:14.00
Max. :3.0000 Max. :2.0000 Max. :4.000 Max. :4.000 Max. :19.00
NA's :3 NA's :1 NA's :1 NA's :2
Score.i Score.s zc zi
Min. :10.00 Min. : 4.00 Min. :-1.8300000 Min. :-1.7300000
1st Qu.:15.00 1st Qu.:11.00 1st Qu.:-0.8600000 1st Qu.:-0.7300000
Median :18.00 Median :15.00 Median : 0.1200000 Median :-0.1300000
Mean :18.65 Mean :14.69 Mean : 0.0008889 Mean : 0.0002326
3rd Qu.:22.00 3rd Qu.:18.00 3rd Qu.: 0.6100000 3rd Qu.: 0.6700000
Max. :34.00 Max. :22.00 Max. : 1.8300000 Max. : 3.0700000
NA's :2 NA's :2
zs AC SSR.c
Min. :-2.58 Min. :1.000 0: 6
1st Qu.:-0.89 1st Qu.:1.000 1:39
Median : 0.08 Median :2.000
Mean : 0.00 Mean :2.047
3rd Qu.: 0.80 3rd Qu.:3.000
Max. : 1.76 Max. :3.000
NA's :2
La voici :
> summary(mydata)
NA. AV.cig AV.alc AV.fru AV.spo
Min. : 1 Min. :1.000 Min. :1.000 Min. :2.000 Min. :1.000
1st Qu.:12 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:3.000 1st Qu.:1.000
Median :23 Median :4.000 Median :3.000 Median :4.000 Median :3.000
Mean :23 Mean :3.545 Mean :2.977 Mean :3.733 Mean :2.733
3rd Qu.:34 3rd Qu.:5.000 3rd Qu.:3.250 3rd Qu.:4.000 3rd Qu.:4.000
Max. :45 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
NA's :1 NA's :1
AV.sel AC.1 AC.2 AC.3 AC.4
Min. :1.000 Min. :1.000 Min. :1.0 Min. :1.000 Min. :1.000
1st Qu.:1.000 1st Qu.:3.750 1st Qu.:2.0 1st Qu.:1.000 1st Qu.:2.000
Median :1.000 Median :4.000 Median :4.0 Median :1.000 Median :3.000
Mean :1.841 Mean :4.023 Mean :3.2 Mean :1.311 Mean :2.956
3rd Qu.:3.000 3rd Qu.:5.000 3rd Qu.:5.0 3rd Qu.:1.000 3rd Qu.:4.000
Max. :5.000 Max. :5.000 Max. :5.0 Max. :4.000 Max. :5.000
NA's :1 NA's :1
AC.5 AC.6 AC.7 AC.8 AC.9
Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.0
1st Qu.:2.000 1st Qu.:2.000 1st Qu.:2.000 1st Qu.:1.000 1st Qu.:1.0
Median :3.000 Median :2.000 Median :3.000 Median :2.000 Median :3.0
Mean :2.711 Mean :2.511 Mean :3.267 Mean :2.186 Mean :2.6
3rd Qu.:4.000 3rd Qu.:3.000 3rd Qu.:4.000 3rd Qu.:3.000 3rd Qu.:4.0
Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.0
NA's :2
AC.10 AC.11 AC.12 AC.13 AC.14
Min. :1.000 Min. :1.000 Min. :1.0 Min. :1.000 Min. :1.000
1st Qu.:2.000 1st Qu.:2.000 1st Qu.:2.0 1st Qu.:1.000 1st Qu.:1.000
Median :3.000 Median :4.000 Median :3.5 Median :2.000 Median :4.000
Mean :3.067 Mean :3.068 Mean :3.0 Mean :2.311 Mean :2.978
3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:4.0 3rd Qu.:3.000 3rd Qu.:4.000
Max. :5.000 Max. :5.000 Max. :5.0 Max. :5.000 Max. :5.000
NA's :1 NA's :1
AC.15 AC.16 AC.17 AP.cig AP.alc
Min. :1.000 Min. :1.000 Min. :1.000 Min. :3.000 Min. :1.000
1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:5.000 1st Qu.:3.000
Median :1.000 Median :2.000 Median :2.000 Median :5.000 Median :3.000
Mean :1.578 Mean :2.318 Mean :2.159 Mean :4.932 Mean :3.465
3rd Qu.:2.000 3rd Qu.:3.250 3rd Qu.:3.000 3rd Qu.:5.000 3rd Qu.:4.000
Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
NA's :1 NA's :1 NA's :1 NA's :2
AP.fru AP.spo AP.sel Sexe Age SSR
Min. :2.000 Min. :1.000 Min. :1.000 F:10 Min. :33.00 Non: 6
1st Qu.:4.000 1st Qu.:3.750 1st Qu.:1.000 H:35 1st Qu.:54.00 Oui:39
Median :4.000 Median :4.000 Median :3.000 Median :58.00
Mean :4.159 Mean :4.045 Mean :2.721 Mean :59.78
3rd Qu.:5.000 3rd Qu.:5.000 3rd Qu.:4.000 3rd Qu.:69.00
Max. :5.000 Max. :5.000 Max. :5.000 Max. :82.00
NA's :1 NA's :1 NA's :2
Tps Diab Obes Hyper Autres Lieu Chcig
Min. : 1.00 Non:40 Non:43 Non:34 Non:35 CA : 6 Min. :0.000
1st Qu.: 1.00 Oui: 5 Oui: 2 Oui:11 Oui:10 HL :36 1st Qu.:0.000
Median : 2.00 MDM: 3 Median :1.000
Mean : 39.09 Mean :1.419
3rd Qu.: 8.00 3rd Qu.:3.000
Max. :336.00 Max. :4.000
NA's :2
Chalc Chfru Chspo Chsel Score.c
Min. :0.0000 Min. :0.0000 Min. :0.000 Min. :0.000 Min. : 4.00
1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.000 1st Qu.:0.000 1st Qu.: 8.00
Median :0.0000 Median :0.0000 Median :1.000 Median :1.000 Median :12.00
Mean :0.5714 Mean :0.4545 Mean :1.386 Mean :0.907 Mean :11.51
3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:2.250 3rd Qu.:1.000 3rd Qu.:14.00
Max. :3.0000 Max. :2.0000 Max. :4.000 Max. :4.000 Max. :19.00
NA's :3 NA's :1 NA's :1 NA's :2
Score.i Score.s zc zi
Min. :10.00 Min. : 4.00 Min. :-1.8300000 Min. :-1.7300000
1st Qu.:15.00 1st Qu.:11.00 1st Qu.:-0.8600000 1st Qu.:-0.7300000
Median :18.00 Median :15.00 Median : 0.1200000 Median :-0.1300000
Mean :18.65 Mean :14.69 Mean : 0.0008889 Mean : 0.0002326
3rd Qu.:22.00 3rd Qu.:18.00 3rd Qu.: 0.6100000 3rd Qu.: 0.6700000
Max. :34.00 Max. :22.00 Max. : 1.8300000 Max. : 3.0700000
NA's :2 NA's :2
zs AC SSR.c
Min. :-2.58 Min. :1.000 0: 6
1st Qu.:-0.89 1st Qu.:1.000 1:39
Median : 0.08 Median :2.000
Mean : 0.00 Mean :2.047
3rd Qu.: 0.80 3rd Qu.:3.000
Max. : 1.76 Max. :3.000
NA's :2
LILOUFB- Nombre de messages : 14
Date d'inscription : 30/12/2016
Re: Matrice de corrélation avec NA...
Je vois plusieurs problèmes :
Vous avez des variables qualitatives (Diab, Obes, Hyper, Autres, Lieu), et donc pas de corrélation possible à calculer pour ces variables. Mais il est vrai que vous ne réclamez pas le calcul de corrélation pour ces variables.
Plus embêtant, vous avez un paquets de données manquantes (NA), ce qui pose de réels problèmes :
Vous devez utiliser l'argument use="na.or.complete" de la fonction cor(), si jamais ca correspond à ce que vous voulez (cf. La documentation de la fonction cor).
Egalement:
HTH, Eric.
Vous avez des variables qualitatives (Diab, Obes, Hyper, Autres, Lieu), et donc pas de corrélation possible à calculer pour ces variables. Mais il est vrai que vous ne réclamez pas le calcul de corrélation pour ces variables.
Plus embêtant, vous avez un paquets de données manquantes (NA), ce qui pose de réels problèmes :
- Code:
> x=rnorm(20)
> y=rnorm(20)
> x[15]=NA
> cor(x,y)
[1] NA
Vous devez utiliser l'argument use="na.or.complete" de la fonction cor(), si jamais ca correspond à ce que vous voulez (cf. La documentation de la fonction cor).
- Code:
> cor(x,y,use="na.or.complete")
[1] 0.01175748
Egalement:
A noter que "complete.obs" s'écrit avec un point "." entre les deux mots. C'est peut-être la source de vos problèmes..LILOUFB a écrit:cor(mydata[,c("Chcig","Chalc","Chfru","Chspo","Chsel","Age","Tps")], use="complete obs")
HTH, Eric.
Eric Wajnberg- Nombre de messages : 1238
Date d'inscription : 14/09/2012
Re: Matrice de corrélation avec NA...
En effet, avec ce détail ça marche beaucoup mieux !
Merci beaucoup
Merci beaucoup
LILOUFB- Nombre de messages : 14
Date d'inscription : 30/12/2016
Page 1 sur 1
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum