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> x1fitfdf1 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]]
On Tue, 3 May 2011, Usha wrote:> 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 listYou have many errors, starting with not reading the posting guide. But the main ones seem to be: (A) A beta distribution has support (0,1). I bet your data are not confined to that interval. If true (and you failed to give the reproducible example the posting guide asked for), then the log-likelihood is -Inf ('not finite') for any value of the parameters. fitdistr() is support software for a book: it is not a tutorial on the basics of maximum-likelihood estimation. (B) As the help says For the following named distributions, reasonable starting values will be computed if ?start? is omitted or only partially specified: ?"cauchy"?, ?"gamma"?, ?"logistic"?, ?"negative binomial"? (parametrized by ?mu? and ?size?), ?"t"? and ?"weibull"?. Since beta is not one of those, you need to specify starting values.> 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)No guarantee that your x1 values are positive, either.> >> 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. >-- 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
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> x1fitfdf1 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.
Thanks for the help. I would like to explain my problem. I have sample of scores from tests which varies form 0 to 35. Now, i want to find out the best fit distribution for this data. I need to order the distributions based on their best fit. For this i am using the function fitdistr(). [One of the Ref.used : FITTING DISTRIBUTIONS WITH R by Vito Ricci. ] Example:> scores<-sample(0:35,500,replace=T) > normalfit<-fitdistr(scores,"normal") > normalfitmean sd 16.8460000 10.1361869 ( 0.4533041) ( 0.3205344)> normalfit$loglik[1] -1867.525 > kstestnormal<-ks.test(scores,"pnorm",16.8460000, 10.1361869) # for the measure of goodness 1) Am i doing the right thing? 2) If yes, can't i follow the same procedure for all the distributions supported by fitdistr? With the start values wherever necessary? 3) Do I have to consider/worry about the warnings that I get? Thanks -- View this message in context: http://r.789695.n4.nabble.com/fitting-distributions-using-fitdistr-MASS-tp3492526p3494532.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]