Error when using fitdist function in R

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Error when using fitdist function in R

PaulJr
Hello everyone,

I  was trying to do some distribution fitting with a numerical field called
Tolls. The sample size = 999 rows.

Basically I assigned the Toll data to a new variable K by doing:
k<-dtest$Toll

After that, tried to fit a gamma distribution by doing: fitG<-fitdist(k,
"gamma")

Then the following messages showed (oh and I checked for empty rows before
doing this):

Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,  :
  NaNs produced
[1] "Error in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
data,  : \n  non-finite finite-difference value [2]\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
data,     ddistnam = ddistname, hessian = TRUE, method = meth, lower =
lower,     upper = upper, ...): non-finite finite-difference value [2]>
Error in fitdist(k, "gamma") :
  the function mle failed to estimate the parameters,
                with the error code 100
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Error when using fitdist function in R

PaulJr
>
> Hello everyone,
>


>
> I  was trying to do some distribution fitting with a numerical field
> called Tolls. The sample size = 999 rows.
>
> Basically I assigned the Toll data to a new variable K by doing:
> k<-dtest$Toll
>
> After that, tried to fit a gamma distribution by doing: fitG<-fitdist(k,
> "gamma")
>
> Then the following messages showed (oh and I checked for empty rows before
> doing this):
>
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L, 313340L,
> :
>   NaNs produced
> [1] "Error in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
> data,  : \n  non-finite finite-difference value [2]\n"
> attr(,"class")
> [1] "try-error"
> attr(,"condition")
> <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
> data,     ddistnam = ddistname, hessian = TRUE, method = meth, lower =
> lower,     upper = upper, ...): non-finite finite-difference value [2]>
> Error in fitdist(k, "gamma") :
>   the function mle failed to estimate the parameters,
>                 with the error code 100
> >
>
>

Any idea of why this is happening?

Best regards,

Paul

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Error when using fitdist function in R

PIKAL Petr
In reply to this post by PaulJr
Hi

where is function fitdist from? Do you by chance mean fitdistr from MASS package?
What is result of str(k)?

Without these questions answered you hardly get any useful answer.

Regards
Petr



> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Paul Bernal
> Sent: Tuesday, April 09, 2013 11:19 PM
> To: [hidden email]
> Subject: [R] Error when using fitdist function in R
>
> Hello everyone,
>
> I  was trying to do some distribution fitting with a numerical field
> called Tolls. The sample size = 999 rows.
>
> Basically I assigned the Toll data to a new variable K by doing:
> k<-dtest$Toll
>
> After that, tried to fit a gamma distribution by doing: fitG<-
> fitdist(k,
> "gamma")
>
> Then the following messages showed (oh and I checked for empty rows
> before doing this):
>
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> [1] "Error in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
> data,  : \n  non-finite finite-difference value [2]\n"
> attr(,"class")
> [1] "try-error"
> attr(,"condition")
> <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs
> =
> data,     ddistnam = ddistname, hessian = TRUE, method = meth, lower =
> lower,     upper = upper, ...): non-finite finite-difference value [2]>
> Error in fitdist(k, "gamma") :
>   the function mle failed to estimate the parameters,
>                 with the error code 100
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Error when using fitdist function in R

Brian Ripley
On 10/04/2013 08:29, PIKAL Petr wrote:
> Hi
>
> where is function fitdist from? Do you by chance mean fitdistr from MASS package?

No, from the output.  More likely

fitdistrplus::fitdist   Fit of univariate distributions to non-censored
                         data

> What is result of str(k)?
>
> Without these questions answered you hardly get any useful answer.

Also, the data seem to be integers: a gamma distribution is for real
positive values only.  Having zero values would give the results you see.

>
> Regards
> Petr
>
>
>
>> -----Original Message-----
>> From: [hidden email] [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Paul Bernal
>> Sent: Tuesday, April 09, 2013 11:19 PM
>> To: [hidden email]
>> Subject: [R] Error when using fitdist function in R
>>
>> Hello everyone,
>>
>> I  was trying to do some distribution fitting with a numerical field
>> called Tolls. The sample size = 999 rows.
>>
>> Basically I assigned the Toll data to a new variable K by doing:
>> k<-dtest$Toll
>>
>> After that, tried to fit a gamma distribution by doing: fitG<-
>> fitdist(k,
>> "gamma")
>>
>> Then the following messages showed (oh and I checked for empty rows
>> before doing this):
>>
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>> 313340L,  :
>>    NaNs produced
>> [1] "Error in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
>> data,  : \n  non-finite finite-difference value [2]\n"
>> attr(,"class")
>> [1] "try-error"
>> attr(,"condition")
>> <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs
>> =
>> data,     ddistnam = ddistname, hessian = TRUE, method = meth, lower =
>> lower,     upper = upper, ...): non-finite finite-difference value [2]>
>> Error in fitdist(k, "gamma") :
>>    the function mle failed to estimate the parameters,
>>                  with the error code 100
>>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.
>


--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Error when using fitdist function in R

PaulJr
In reply to this post by PIKAL Petr
Dear PIKAL,

Thank you for your kind reply. The function fitdist comes from package
fitdistrplus. I am attaching a .csv document that contains the data I want
to fit a distribution to, so you can have a good idea of what kind of data
I am dealing with.

Basically what str(k) contains is the information that appears in the
column Toll in the .csv document I am attaching. I will also show you the
result of str(k), for your reference:

 int [1:499] 363328 376216 367032 314826 311892 313340 367106 227742 386744
372002 ...

Hope this helps explain my situation better,

Best regards,

Paul

2013/4/10 PIKAL Petr <[hidden email]>

> Hi
>
> where is function fitdist from? Do you by chance mean fitdistr from MASS
> package?
> What is result of str(k)?
>
> Without these questions answered you hardly get any useful answer.
>
> Regards
> Petr
>
>
>
> > -----Original Message-----
> > From: [hidden email] [mailto:r-help-bounces@r-
> > project.org] On Behalf Of Paul Bernal
> > Sent: Tuesday, April 09, 2013 11:19 PM
> > To: [hidden email]
> > Subject: [R] Error when using fitdist function in R
> >
> > Hello everyone,
> >
> > I  was trying to do some distribution fitting with a numerical field
> > called Tolls. The sample size = 999 rows.
> >
> > Basically I assigned the Toll data to a new variable K by doing:
> > k<-dtest$Toll
> >
> > After that, tried to fit a gamma distribution by doing: fitG<-
> > fitdist(k,
> > "gamma")
> >
> > Then the following messages showed (oh and I checked for empty rows
> > before doing this):
> >
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> > 313340L,  :
> >   NaNs produced
> > [1] "Error in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
> > data,  : \n  non-finite finite-difference value [2]\n"
> > attr(,"class")
> > [1] "try-error"
> > attr(,"condition")
> > <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs
> > =
> > data,     ddistnam = ddistname, hessian = TRUE, method = meth, lower =
> > lower,     upper = upper, ...): non-finite finite-difference value [2]>
> > Error in fitdist(k, "gamma") :
> >   the function mle failed to estimate the parameters,
> >                 with the error code 100
> > >
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-<http://www.r-project.org/posting->
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Error when using fitdist function in R

PaulJr
In reply to this post by Brian Ripley
Dear Dr. Brian,

Hope you are doing well. The thing is that my data does not have any 0s in
it. Furthermore, I also tried fitting other distributions (i.e. weibull)
and still did not work.

I will show you the results of str(k) so you have an idea of the tipe of
data I am dealing with:

 int [1:499] 363328 376216 367032 314826 311892 313340 367106 227742 386744
372002 ...
I will also attach, the .csv file that contains the data I am working with,
for your reference.

Any help you can provide me with will be greatly appreciated,

Best regards and thanks for your kind reply,

Paul



2013/4/10 Prof Brian Ripley <[hidden email]>

> On 10/04/2013 08:29, PIKAL Petr wrote:
>
>> Hi
>>
>> where is function fitdist from? Do you by chance mean fitdistr from MASS
>> package?
>>
>
> No, from the output.  More likely
>
> fitdistrplus::fitdist   Fit of univariate distributions to non-censored
>                         data
>
>
> What is result of str(k)?
>>
>> Without these questions answered you hardly get any useful answer.
>>
>
> Also, the data seem to be integers: a gamma distribution is for real
> positive values only.  Having zero values would give the results you see.
>
>
>
>> Regards
>> Petr
>>
>>
>>
>> -----Original Message-----
>>> From: [hidden email] [mailto:r-help-bounces@r-
>>> project.org] On Behalf Of Paul Bernal
>>> Sent: Tuesday, April 09, 2013 11:19 PM
>>> To: [hidden email]
>>> Subject: [R] Error when using fitdist function in R
>>>
>>> Hello everyone,
>>>
>>> I  was trying to do some distribution fitting with a numerical field
>>> called Tolls. The sample size = 999 rows.
>>>
>>> Basically I assigned the Toll data to a new variable K by doing:
>>> k<-dtest$Toll
>>>
>>> After that, tried to fit a gamma distribution by doing: fitG<-
>>> fitdist(k,
>>> "gamma")
>>>
>>> Then the following messages showed (oh and I checked for empty rows
>>> before doing this):
>>>
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
>>> 313340L,  :
>>>    NaNs produced
>>> [1] "Error in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
>>> data,  : \n  non-finite finite-difference value [2]\n"
>>> attr(,"class")
>>> [1] "try-error"
>>> attr(,"condition")
>>> <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs
>>> =
>>> data,     ddistnam = ddistname, hessian = TRUE, method = meth, lower =
>>> lower,     upper = upper, ...): non-finite finite-difference value [2]>
>>> Error in fitdist(k, "gamma") :
>>>    the function mle failed to estimate the parameters,
>>>                  with the error code 100
>>>
>>>>
>>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________**________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**posting-<http://www.r-project.org/posting->
>>> guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>> ______________________________**________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> --
> Brian D. Ripley,                  [hidden email]
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~**ripley/<http://www.stats.ox.ac.uk/~ripley/>
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Error when using fitdist function in R

PIKAL Petr
In reply to this post by PaulJr
Hi

I think you get some answer from prof.Ripley.  However when I did

hist(k)
plot(density(k))

it seems to me, that k is mixture of 2 normal distributions. So you probably cannot fit any single distribution to it.

Regards
Petr

From: Paul Bernal [mailto:[hidden email]]
Sent: Wednesday, April 10, 2013 3:05 PM
To: PIKAL Petr
Cc: [hidden email]
Subject: Re: [R] Error when using fitdist function in R

Dear PIKAL,

Thank you for your kind reply. The function fitdist comes from package fitdistrplus. I am attaching a .csv document that contains the data I want to fit a distribution to, so you can have a good idea of what kind of data I am dealing with.

Basically what str(k) contains is the information that appears in the column Toll in the .csv document I am attaching. I will also show you the result of str(k), for your reference:

 int [1:499] 363328 376216 367032 314826 311892 313340 367106 227742 386744 372002 ...

Hope this helps explain my situation better,

Best regards,

Paul
2013/4/10 PIKAL Petr <[hidden email]<mailto:[hidden email]>>
Hi

where is function fitdist from? Do you by chance mean fitdistr from MASS package?
What is result of str(k)?

Without these questions answered you hardly get any useful answer.

Regards
Petr



> -----Original Message-----
> From: [hidden email]<mailto:[hidden email]> [mailto:r-help-bounces@r-<mailto:r-help-bounces@r->
> project.org<http://project.org/>] On Behalf Of Paul Bernal
> Sent: Tuesday, April 09, 2013 11:19 PM
> To: [hidden email]<mailto:[hidden email]>
> Subject: [R] Error when using fitdist function in R
>
> Hello everyone,
>
> I  was trying to do some distribution fitting with a numerical field
> called Tolls. The sample size = 999 rows.
>
> Basically I assigned the Toll data to a new variable K by doing:
> k<-dtest$Toll
>
> After that, tried to fit a gamma distribution by doing: fitG<-
> fitdist(k,
> "gamma")
>
> Then the following messages showed (oh and I checked for empty rows
> before doing this):
>
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> Warning in dgamma(c(363328L, 376216L, 367032L, 314826L, 311892L,
> 313340L,  :
>   NaNs produced
> [1] "Error in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs =
> data,  : \n  non-finite finite-difference value [2]\n"
> attr(,"class")
> [1] "try-error"
> attr(,"condition")
> <simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs
> =
> data,     ddistnam = ddistname, hessian = TRUE, method = meth, lower =
> lower,     upper = upper, ...): non-finite finite-difference value [2]>
> Error in fitdist(k, "gamma") :
>   the function mle failed to estimate the parameters,
>                 with the error code 100
> >
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email]<mailto:[hidden email]> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-<http://www.r-project.org/posting->
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.