[R] making spearman correlation cor() call fail with log(0) as input
tshtatland at gmail.com
Fri Sep 12 02:02:31 CEST 2008
You are right, Inf and -Inf are not considered errors in R, they are
accepted as input to Spearman's cor(), and so I will have to check the
input myself for such condition.
Thank you for pointing this out!
On Wed, Sep 10, 2008 at 8:50 PM, Greg Snow <Greg.Snow at imail.org> wrote:
> Your code shows no errors only correct responses.
> If you want an error when R is generating correct results, you will need to check for the conditions yourself.
> -----Original Message-----
> From: "Timur Shtatland" <tshtatland at gmail.com>
> To: "r-help at r-project.org" <r-help at r-project.org>
> Sent: 9/10/08 3:51 PM
> Subject: [R] making spearman correlation cor() call fail with log(0) as input
> How can I make the cor(x, y, method="spearman") call to produce an
> error when the input to it (x, y) produces an error? Here is a simple
>> a <- c(0, 1, 2)
>> b <- c(100, 2, 4)
> ## error:
>  -Inf 0.0000000 0.6931472
> ## error, as expected:
>> cor(log(a), log(b), method="pearson")
>  NaN
> ## not an error any more (not expected):
>> cor(log(a), log(b), method="spearman")
>  -0.5
>> cor(log(a), log(b), method="spearman", use="all.obs")
>  -0.5
> R version 2.6.1 (2007-11-26)
> attached base packages:
>  stats graphics grDevices utils datasets methods base
> Thank you for your help.
> Best regards,
> Timur Shtatland
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help