[R] Problem with fitdistr for beta

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jul 4 18:38:02 CEST 2003


rbeta(100,0.1,0.1) is generating samples which contain 1, an impossible 
value for a beta and hence the sample has an infinite log-likelihood.
It is clearly documented on the help page that the range is 0 < x < 1.
However, that is not so surprising as P(X > 1-1e-16) is about 1% and hence 
values will get rounded to one.

The same would happen for a value of 0.

Your code is syntactically incorrect, at least as received here.

On Fri, 4 Jul 2003, Agustin Lobo wrote:

> 
> I have the following problem:
> 
> I have a vector x of data (0<x<=1 ) with
> a U-shaped histogram and try to fit a beta
> distribution using  fitdistr. In fact,
> hist(rbeta(100,0.1,0.1)) looks a lot like
> my data.
> 
> The equivalent to
> the example in the manual
> sometimes work:
> 
> > a <- rbeta(100,0.1,0.1)
> > fitdistr(x=a, "beta", start=list(shape1=0.1,shape2=0.1))1)
> >      shape1       shape2
>   0.09444627   0.12048753
>  (0.01120670) (0.01550129)
> 
> but sometimes does not:
> > a <- rbeta(100,0.1,0.1)
> > fitdistr(x=a, "beta", start=list(shape1=0.1,shape2=0.1))1)
> > Error in optim(start, mylogfn, x = x, hessian = TRUE, ...) :
>         Function cannot be evaluated at initial parameters
> 
> Unfortunately, my data fall in the second case
> 
> I've searched for any weird value that be present in the
> cases in which fitdistr exits with the error message, but
> could not find any.
> 
> Any help?
> (please if anyone answers be sure to answer to my address as well,
> I cannot subscribe to the list)
> 
> Thanks
> 
> Agus
> 
> Dr. Agustin Lobo
> Instituto de Ciencias de la Tierra (CSIC)
> Lluis Sole Sabaris s/n
> 08028 Barcelona SPAIN
> tel 34 93409 5410
> fax 34 93411 0012
> alobo at ija.csic.es
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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




More information about the R-help mailing list