cberry@tajo.ucsd.edu
2004-Jan-21 00:18 UTC
[Rd] 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) ) # OKError 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
Peter Dalgaard
2004-Jan-21 00:59 UTC
[Rd] cor( x, y , method = "spearman" ) incorrect if any( is.na(c( x, y (PR#6448)
cberry@tajo.ucsd.edu writes:> 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 > } > }That one got fixed a while back for r-devel, by using na.last="keep" in the apply call, which is effectively the same fix. Looks like it was never filed in r-bugs. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
Maybe Matching Threads
- cor(x,y) when is.null(y) (PR#883)
- unz( "x.zip", "y.csv" ) != pipe( "unzip -p x.zip y.csv" )
- loglin( tab, margin, start = bad.start ) kills R (PR#7123)
- rug(x) clip warning incorrect if par("xlog")==TRUE (PR#1188)
- substitute(x$y)) corrupts 'y' component (PR#731)