[R] cor function in R 1.8.0

mli@access4less.net mli at access4less.net
Sat Oct 18 02:53:40 CEST 2003


Dear R users,

Does anyone know why the following two ways to calculate
correlation variance give different answers? I also obtain
different answers when I use, say, "spearman" method in
cor(). The problem does not happen in R 1.7.1 ("pearson"
correlation only, of course in R 1.7.1).

> set.seed(1234)
> x <- matrix(rnorm(10*5),10,5)
> y1 <- cor(x)
> y2 <- cor(x, use="pair")
> y1;y2
           [,1]        [,2]       [,3]        [,4]       
[,5]
[1,]  1.0000000 -0.17528322 -0.5528785 -0.33876389
-0.49755947
[2,] -0.1752832  1.00000000 -0.2776360 -0.04840035 
0.05265522
[3,] -0.5528785 -0.27763602  1.0000000  0.16272829 
0.38392034
[4,] -0.3387639 -0.04840035  0.1627283  1.00000000 
0.85404798
[5,] -0.4975595  0.05265522  0.3839203  0.85404798 
1.00000000
           [,1]        [,2]       [,3]        [,4]       
[,5]
[1,]  1.0000000 -0.17348156 -0.5523156 -0.33585411
-0.48292994
[2,] -0.1734816  0.99965819 -0.2743654 -0.04417098 
0.05661364
[3,] -0.5523156 -0.27436539  0.9990913  0.16439438 
0.38457068
[4,] -0.3358541 -0.04417098  0.1643944  0.99862845 
0.85389126
[5,] -0.4829299  0.05661364  0.3845707  0.85389126 
0.99985356

Thanks,

Ming-Chung Li




More information about the R-help mailing list