Ng Stanley
2008-Mar-08 07:04 UTC
[R] how to compute uncentered (pearson correlation) correlation efficiently
Hi, Seeking suggestions to compute uncentered (pearson correlation) correlation efficiently. corr from stats library works on x and y columns. dist from amap library works on x and y rows. My data layout is slightly different such that row(i) of matrix x is compared to row(i) of matrix y. Thanks [[alternative HTML version deleted]]
David Winsemius
2008-Mar-08 20:00 UTC
[R] how to compute uncentered (pearson correlation) correlation efficiently
"Ng Stanley" <stanleyngkl at gmail.com> wrote::> Seeking suggestions to compute uncentered (pearson correlation) > correlation efficiently. > > corr from stats library works on x and y columns. dist from amap > library works on x and y rows. > > My data layout is slightly different such that row(i) of matrix x > is compared to row(i) of matrix y.Do you mean cor()?> ?corrNo documentation for 'corr' in specified packages and libraries: you could try 'help.search("corr")' I do not think that cor() will complain when you send it rows rather than columns. r25 <- matrix(rnorm(25),ncol=5) q25 <- matrix(rnorm(25),ncol=5)> r25[,1] [,2] [,3] [,4] [,5] [1,] 0.9075305 0.1768761 0.9946014 -2.1863247 -1.4031437 [2,] -0.6675117 0.5282182 -0.2522370 -0.3905784 -1.7219424 [3,] 0.7975418 -0.1992466 0.8884690 2.4123639 -0.9834216 [4,] 0.4027469 1.7962510 -0.1084113 0.7382887 0.2165000 [5,] -1.3969290 1.3095061 0.8976753 0.5161417 -2.0408553> cor(q25[,1],r25[,1])[1] 0.4221951> cor(q25[1,],r25[1,])[1] -0.4903181 -- David Winsemius