[R] correlating values
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Tue May 30 17:36:10 CEST 2006
Ahamarshan jn wrote:
> I did a correlation for the values
>
> - EX4577 EX4599 EX4566 EX4522
> WL917 2.53528 0.79077 0.21499 -0.01084
> WP429S -0.192723715
> WP819 -1.016997552
> WP977 1.378674 -0.07071 0.625089 0.4728363
> WI205S -0.24443 -1.789526 0.648923 -0.775867
>
>
> by using
> round(cor(t(person.data),use="pairwise.complete.obs"))
>
> i got the result as
>
> - WL917 WP429S WP819 WP977 WI205S
> WL917 1 NA NA 0.344 -0.11424
> WP429S NA NA NA NA NA
> WP819 NA NA NA NA NA
> WP977 0.34461 NA NA 1 .23294
> WI205S -0.11424NA NA 0.23294 1
>
> i notice that
> for correlation between WP429S x wp429S the value is
> given as NA where as it should be 1
> same is the case with WP819 x WP819
>
> Can someone please help me reason out why this is
> happening? and any corrective measure that I need to
> take so that I can get the true value of 1 for them.
>
> Thank you
> - ash#
>
Hi, Ash,
It's difficult to tell with the data you provided (maybe just poor email
formatting), but it looks like both WP429S and WP819 have only one
value. You cannot obtain a correlation with only one value (see any
intro stats book for the definition or correlation or just Google it). Try:
x <- rnorm(1)
y <- rnorm(1)
cor(x, y)
cor(matrix(x, 1, 1))
This is because x and y have zero variance. Forcing the "NA" to "1" as a
"corrective measure" would be incorrect and misleading.
HTH,
--sundar
More information about the R-help
mailing list