[R] cor and missing values. Bug?

Robert W. Baer, Ph.D. rbaer at atsu.edu
Wed May 26 15:43:56 CEST 2004


> Not to put too fine a point on it, but did you consider checking the
> NEWS file for the most recent version (1.9.0,
> http://cran.r-project.org/src/base/NEWS)?
>
>     o   The cor() function did not remove missing values in the
>         non-Pearson case.


There is still something a little strange in version 1.9.0. What  is the
source of the discrpancy between cor() and cor.test()?

> vec1 <- 1:10
> vec2 <- 2*vec1
> vec1[c(1, 5)] <- NA
> cor(vec1[-c(1,5)], vec2[-c(1,5)], use="pair", method="spearman")
[1] 1
> cor(vec1, vec2, use="complete", method="spearman")
[1] 0.99544
> cor.test(vec1, vec2, use="complete", method="spearman")

        Spearman's rank correlation rho

data:  vec1 and vec2
S = 0, p-value = 4.96e-05
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
  1

Rob Baer




More information about the R-help mailing list