[R] Correlation question

Stephane Vaucher vauchers at iro.umontreal.ca
Wed Sep 8 21:35:21 CEST 2010


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"                   "P3"
[19] "P4"                   "P5"                   "P6"
[22] "P8"                   "P9"                   "P10"
[25] "P11"                  "P12"                  "P7"
[28] "SITE"                 "Errors"               "warnings"
[31] "Manual"               "Total"                "H_tot"
[34] "HP1.1"                "HP1.2"                "HP1.3"
[37] "HP1.4"                "HP_tot"               "HO1.1"
[40] "HO1.2"                "HO1.3"                "HO1.4"
[43] "HO_tot"               "HU1.1"                "HU1.2"
[46] "HU1.3"                "HU_tot"               "HR"
[49] "L_tot"                "LP1.1"                "LP1.2"
[52] "LP1.3"                "LP1.4"                "LP_tot"
[55] "LO1.1"                "LO1.2"                "LO1.3"
[58] "LO1.4"                "LO_tot"               "LU1.1"
[61] "LU1.2"                "LU1.3"                "LU_tot"
[64] "LR_tot"               "SP_tot"               "SP1.1"
[67] "SP1.2"                "SP1.3"                "SP1.4"
[70] "SP_tot.1"             "SO1.1"                "SO1.2"
[73] "SO1.3"                "SO1.4"                "SO_tot"
[76] "SU1.1"                "SU1.2"                "SU1.3"
[79] "SU_tot"               "SR"

Thank you in advance,
Stephane Vaucher



More information about the R-help mailing list