[R] NaNS Error Message
PIKAL Petr
petr.pikal at precheza.cz
Wed Mar 27 08:19:55 CET 2013
Hi
If you can not share information you need to solve your problems yourself.
you can trace code by some print statements
sn<-(S-n);snfact<-gamma(sn); print(sn)
or use
?debug
as Sarah pointed out, n is probably greater than 100 and in that case gamma(sn) results in NaN.
Regards
Petr
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Sahana Srinivasan
> Sent: Tuesday, March 26, 2013 4:52 PM
> To: Berend Hasselman
> Cc: r-help at r-project.org
> Subject: Re: [R] NaNS Error Message
>
> Hi, sorry I can't provide the reproducible code - the formula is
> currently being worked on for a research paper so I can't really give
> out details in that regard.
> That being said, k is initialized to 1 at the beginning of the loop. n
> has various values (whole numbers, 0 or greater, no upper limit).
>
>
>
> On Tue, Mar 26, 2013 at 3:41 PM, Berend Hasselman <bhh at xs4all.nl>
> wrote:
>
> >
> > On 26-03-2013, at 16:25, Sahana Srinivasan
> > <sahanasrinivasan.91 at gmail.com>
> > wrote:
> >
> > > Hi,
> > > I'm using R to do a series of calculation and I have gotten several
> > > warnings that say "NaNS produced". Whatever I could read on line
> > > gives me an idea that this warning is produced when the number is
> > > use is a
> > negative
> > > log or otherwise mathematically problematic.
> > > I'm getting this error while using factorial() and gamma () on
> > > strictly positive numbers (always greater than zero).
> > > Here is a snippet of my code:
> > > k goes from 1 to a positive limit.
> > > S is always 100.
> > > Only positive values of n are allowed into the loop.
> > >
> > > if(n>0)
> > > {
> > > while(k<=lim)
> > > {
> > >
> > > sn<-(S-n);snfact<-gamma(sn);
> > > sn2<-(2-n+S);sn2gam<-gamma(sn2);
> > >
> > > num<-(ngam*sn2gam);
> > >
> > >
> > > nk2<-(2+k-(2*n)+S);
> > > nk2gam<-gamma(nk2);
> > > den<-(k*nk2gam);
> > > prob<-(num/den);
> > >
> > > sum<-(as.numeric((k*prob))+sum);
> > >
> > > k<-k+1;
> > > }
> > > }
> > >
> > > The error message received for every instance of this loop is :
> > > In gamma(sn) : NaNs produced
> > > In gamma(sn2) : NaNs produced
> > > In gamma(nk2) : NaNs produced
> > >
> >
> > This not reproducible code.
> > Where is ngam?
> > Where is k set to 1?
> > What value does n have?
> >
> > Berend
> >
> >
>
> [[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.
More information about the R-help
mailing list