cor( x, y , method = "spearman" ) incorrect if any( is.na(c( x, y (PR#6448)
version
_ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 8.1 year 2003 month 11 day 21 language R
cor( 1:3, rep(NA,3) ) # OK
Error in cor(1:3, rep(NA, 3)) : missing observations in cov/cor
cor( 1:3, rep(NA,3), method="spearman" ) # OUCH!!
[1] 1
I think this would fix cor( ), but have not looked at the C-code for
additional gotcha's:
if (method != "pearson") {
Rank <- function(u) if (is.matrix(u))
apply(u, 2, rank)
else rank(u)
+ x.na <- is.na(x)
x <- Rank(x)
+ is.na( x ) <- x.na
if (!is.null(y)) {
+ y.na <- is.na(y)
y <- Rank(y)
+ is.na(y) <- y.na
}
}
Chuck
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry@tajo.ucsd.edu UC San Diego
http://hacuna.ucsd.edu/members/ccb.html La Jolla, San Diego 92093-0717