[R] Error while using fitdistr() function or goodfit() function

Jason Q. McClintic jqmcclintic at stthomas.edu
Sun Feb 10 17:28:00 CET 2008


Try changing your method to "ML" and try again. I tried the run the
first example from the documentation and it failed with the same error.
Changing the estimation method to ML worked.

@List: Can anyone else verify the error I got? I literally ran the
following two lines interactively from the example for goodfit:

dummy <- rnbinom(200, size = 1.5, prob = 0.8)
gf <- goodfit(dummy, type = "nbinomial", method = "MinChisq")

and got back

Warning messages:
1: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced
2: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced

Again, I hope this helps.

Sincerely,

Jason Q. McClintic

Aswad Gurjar wrote:
> Hello,
>  
> Thanks for help.But I am facing different problem.
>  
> I have 421 readings of time and no of requests coming at perticular time.Basically I have data with interval of one minute and corresponding no of requests.It is discrete in nature.I am collecting data from 9AM to 4PM.But some of readings are coming as 0.When I plotted histogram of data I could not get shape of any standard distribution.Now,my aim is to find distribution which is "best fit" to my data among standard ones.
>  
>  So there was huge data.That's why I tried to collect data into no of bins.That was working properly.Whatever code you have given is working properly too.But your code is more efficient.Now,problem comes at next stage.When I apply fitdistr() for continuous data or goodfit() for discrete data I get following error.I am not able to remove that error.Please help me if you can.
> Errors are as follows:
> library(vcd)
> gf<-goodfit(binCount,type= "nbinomial",method= "MinChisq")
> Warning messages:
> 1: NaNs produced in: pnbinom(q, size, prob, lower.tail, log.p) 
> 2: NaNs produced in: pnbinom(q, size, prob, lower.tail, log.p) 
> 3: NaNs produced in: pnbinom(q, size, prob, lower.tail, log.p) 
> 4: NaNs produced in: pnbinom(q, size, prob, lower.tail, log.p) 
> 5: NaNs produced in: pnbinom(q, size, prob, lower.tail, log.p) 
>> summary(gf)
>  
>          Goodness-of-fit test for nbinomial distribution
>  
>              X^2 df    P(> X^2)
> Pearson 9.811273  2 0.007404729
> Warning message:
> Chi-squared approximation may be incorrect in: summary.goodfit(gf)
>  
> for another distribution: 
>  gf<-goodfit(binCount,type= "poisson",method= "MinChisq")
> Warning messages:
> 1: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
> 2: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
> 3: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
> 4: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
> 5: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
> 6: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
> 7: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
> 8: NA/Inf replaced by maximum positive value in: optimize(chi2, range(count)) 
>  Goodness-of-fit test for poisson distribution
>  
>                   X^2 df P(> X^2)
> Pearson 1.660931e+115  3        0
> Warning message:
> Chi-squared approximation may be incorrect in: summary.goodfit(gf)
>  
>  
> Aswad
> On 2/10/08, Jason Q. McClintic < jqmcclintic at stthomas.edu> wrote: 
> 
> I get the digest, so I apologize if this is a little late.
> 
> For your situation (based on the description and what I think your code
> is doing, more on that below), it looks like you are modeling a Poisson
> flow where the number of hits per unit time is a random integer with
> some mean value.
> 
> If I understand your code correctly, you are trying to put your data
> into k bins of width f<-(max(V1)-min(V1))/k. In that case I would think
> something like this would work more efficiently:
> 
> m<-min(V1);
> k<-floor(1 + log2(length(V1)));
> f<-(max(V1)-min(V1))/k;
> binCount<-NULL;
> for(i in seq(length=k)){
> binIndex<-which((m+(i-1)*f<V1)&(V1<m+i*f));
> binCount[i]<-sum(V2[binIndex]);
> };
> 
> where i becomes the index of time intervals.
> 
> Hope it helps.
> 
> Sincerely,
> 
> Jason Q. McClintic
> 
> r-help-request at r-project.org wrote:
>> Send R-help mailing list submissions to
>>       r-help at r-project.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>       https://stat.ethz.ch/mailman/listinfo/r-help
>> or, via email, send a message with subject or body 'help' to
>>       r-help-request at r-project.org
>>
>> You can reach the person managing the list at
>>       r-help-owner at r-project.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of R-help digest..."
>>
> 
> 
>



More information about the R-help mailing list