[R] Spearman correlation and missing observations
Nicolas STRANSKY
Nicolas.Stransky at curie.fr
Wed Nov 26 13:47:09 CET 2003
Hi,
I am using R 1.8.1 on WinXP. I encounter a problem when trying to
compute a Spearman correlation under certain conditions (at least I
think there is a problem, but maybe this is the normal behavior).
> X<-array(0,c(20,2))
>
> X[,1]<-c(runif(10),rep(NA,10))
> X[,2]<-c(runif(10),rep(NA,10))
>
> Y<-X[1:10,]
>
> cor(Y,method="s",use="complete.obs")
[,1] [,2]
[1,] 1.0000000 0.3939394
[2,] 0.3939394 1.0000000
> cor(X,method="s",use="complete.obs")
[,1] [,2]
[1,] 1.000000 0.924812
[2,] 0.924812 1.000000
The problem is that I do not get the same results whenever there are
NA's is the dataset or not. Perhaps I misunderstand the use of
"complete.obs" and "pairwise.complete.obs" for dealing with missing data
; if so, please tell me how I could manage to have se same result at the
end.
On the other hand, the same type of commands with a Pearson correlation
gives exactly the same result for X and Y :
> cor(Y,method="p",use="complete.obs")
[,1] [,2]
[1,] 1.0000000 0.3109109
[2,] 0.3109109 1.0000000
> cor(X,method="p",use="complete.obs")
[,1] [,2]
[1,] 1.0000000 0.3109109
[2,] 0.3109109 1.0000000
Thank's for your help
--
Nicolas STRANSKY
Institut Curie - UMR 144 du CNRS
26, rue d'Ulm - 75248 Paris Cedex 05
tel : 01.42.34.63.40 / fax : 01.42.34.63.49
More information about the R-help
mailing list