[R] Warning message:In pt(q, df, lower.tail, log.p) : NaNs produced

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Jan 6 13:22:02 CET 2009


Yihui Xie wrote:
> Obviously your df=0 in pt(STATISTIC, df).

However, there are 3 complete observation pairs, not 2, and he wants r
as the off-diagonal element and not the whole correlation matrix.

(and df denotes two different things, but that is just aesthetics.)

> 
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
> Mobile: +86-15810805877
> Homepage: http://www.yihui.name
> School of Statistics, Room 1037, Mingde Main Building,
> Renmin University of China, Beijing, 100872, China
> 
> 
> 
> On Tue, Jan 6, 2009 at 7:26 PM, Moumita Das
> <das.moumita.online at gmail.com> wrote:
>> Hi friends,
>> Any idea why do i get this warning?And also why all computed p-values are
>> NaN.
>> Have shown below what i did in Windows r-console.:--
>>> df
>>  c1 c2
>> 1  1 50
>> 2 NA NA
>> 3  4 NA
>> 4  7  6
>> 5 NA  7
>> 6 10 10
>>> r<-cor(x=df,y=NULL,use="complete.obs",method=c("pearson"))
>>> r
>>           c1         c2
>> c1  1.0000000 -0.9148074
>> c2 -0.9148074  1.0000000
>>> cor.p.values<- function(r, n)
>> + {
>> +   df <- n - 2
>> +   ESTIMATE <- c(cor = r)
>> +   PARAMETER <- c(df = df)
>> +   STATISTIC <- c(sqrt(df) * r / sqrt(1 - r^2))
>> +   p <- pt(STATISTIC, df)
>> +   return(2 * pmin(p, 1 - p))
>> + }
>>> cor.p.values(r,2)
>> [1] NaN NaN NaN NaN
>> *Warning message:
>> In pt(q, df, lower.tail, log.p) : NaNs produced
>> *
>> Any help will be appreciated.. :)
>> --
>> Thanks
>> Moumita
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list