Correlation question
Hi,
Does your data have missing values? I am not sure it would change
anything, but perhaps try adding:
cor(test2, method = "spearman", use = "pairwise.complete.obs")
or something of the like. I am not sure what R does by default. My
reasoning stems from this particular passage in the documentation:
If ?use? is ?"everything"?, ?NA?s will propagate conceptually,
i.e., a resulting value will be ?NA? whenever one of its
contributing observations is ?NA?.
I do not think the names should make a difference (unless you're
talking about human error).
Best regards,
Josh
On Wed, Sep 8, 2010 at 12:35 PM, Stephane Vaucher
<vauchers at iro.umontreal.ca> wrote:
Hi everyone, I'm observing what I believe is weird behaviour when attempting to do something very simple. I want a correlation matrix, but my matrix seems to contain correlation values that are not found when executed on pairs:
test2$P2
?[1] 2 2 4 4 1 3 2 4 3 3 2 3 4 1 2 2 4 3 4 1 2 3 2 1 3
test2$HP_tot
?[1] ?10 ?10 ?10 ?10 ?10 ?10 ?10 ?10 136 136 136 136 136 136 136 136 136 136 ?15 [20] ?15 ?15 ?15 ?15 ?15 ?15 c=cor(test2$P3,test2$HP_tot,method='spearman')
c
[1] -0.2182876
c=cor(test2,method='spearman')
Warning message: In cor(test2, method = "spearman") : the standard deviation is zero
write(c,file='out.csv')
from my spreadsheet -0.25028783918741 Most cells are correct, but not that one. If this is expected behaviour, I apologise for bothering you, I read the documentation, but I do not know if the calculation of matrices and pairs is done using the same function (eg, with respect to equal value observations). If this is not a desired behaviour, I noticed that it only occurs with a relatively large matrix (I couldn't reproduce on a simple 2 column data set). There might be a naming error.
names(test2)
?[1] "ID" ? ? ? ? ? ? ? ? ? "NOMBRE" ? ? ? ? ? ? ? "MAIL" ?[4] "Age" ? ? ? ? ? ? ? ? ?"SEXO" ? ? ? ? ? ? ? ? "Studies" ?[7] "Hours_Internet" ? ? ? "Vision.Disabilities" ?"Other.disabilities" [10] "Technology_Knowledge" "Start_Time" ? ? ? ? ? "End_Time" [13] "Duration" ? ? ? ? ? ? "P1" ? ? ? ? ? ? ? ? ? "P1Book" [16] "P1DVD" ? ? ? ? ? ? ? ?"P2" ? ? ? ? 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_tot" [76] "SU1.1" ? ? ? ? ? ? ? ?"SU1.2" ? ? ? ? ? ? ? ?"SU1.3" [79] "SU_tot" ? ? ? ? ? ? ? "SR" Thank you in advance, Stephane Vaucher
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/