[R] fitting distributions using fitdistr (MASS)

Ravi Varadhan rvaradhan at jhmi.edu
Tue May 3 16:37:16 CEST 2011


Your simulation example is bad.  You cannot fit a beta distribution to a data that is not in [0,1], leave alone negative data.

x <- runif(1007)

fitdistr(x, "beta", start=list(shape1=0.5, shape2=0.5))


But try this instead:

x <- runif(100, 1, 27)

fitdistr(x, "beta", start=list(shape1=0.5, shape2=0.5))

It seems that when "beta" and "chi-squared" are specified as the distribution to be estimated, the "start" parameter for optimization have to be specified by the user.  The code does not use any default starting value.
 
Ravi.
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Usha [usha.nair at tcs.com]
Sent: Tuesday, May 03, 2011 5:53 AM
To: r-help at r-project.org
Subject: [R] fitting distributions using fitdistr (MASS)

Please guide me through to resolve the error message that I get

this is what i have done.

>x1<- rnorm(100,2,1)
>x1fitbeta<-fitdistr(x1,"beta")
Error in fitdistr(x1, "beta") : 'start' must be a named list

Yes, I do understand that sometime for the distribution to converge to the
given set of data, it requires initial parameters of the distribution, to
start off with. Hence, i tried this

>x1fitbeta<-fitdistr(x1,densfun=dbeta, start=list(shape1=2,shape2=3))
Error in optim(x = c(1.89074018737135, 1.52649293971978, 2.19950245230280,
:
  initial value in 'vmmin' is not finite

I tried with "f" and "chi-square" what i did with  "t". Please find below
the output.

> x1fitt<-fitdistr(x1,"t")
Error in fitdistr(x1, "t") : optimization failed
In addition: Warning messages:
1: In log(s) : NaNs produced
2: In log(s) : NaNs produced
3: In log(s) : NaNs produced
4: In log(s) : NaNs produced
5: In log(s) : NaNs produced
6: In log(s) : NaNs produced

> x1fitt<-fitdistr(x1,"t", df=1)
Warning messages:
1: In log(s) : NaNs produced
2: In log(s) : NaNs produced


> x1fitf<-fitdistr(x1,"f",start=list(df1=2,df2=3))
Warning message:
In df(x, df1, df2, log) : NaNs produced
> x1fitf
      df1         df2
  5.6733242   4.4962519
 (1.3407776) (0.9016752)

>x1fitchi<-fitdistr(x1,"chi-squared",df=3)
Error in fitdistr(x1, "chi-squared", df = 3) :
  'start' must be a named list

It is the same as what i gave for beta?!!

> x1fitbeta<-fitdistr(x1,"beta", start=list(shape1=2,shape2=3))
Error in optim(x = c(1.89074018737135, 1.52649293971978, 2.19950245230280,
:
  initial value in 'vmmin' is not finite

What is the right syntax....why do I get error for only some, what are the
exceptions?
I dont know how rectify this error. please resolve

Thanks in advance.

--
View this message in context: http://r.789695.n4.nabble.com/fitting-distributions-using-fitdistr-MASS-tp3492103p3492103.html
Sent from the R help mailing list archive at Nabble.com.
        [[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