On 13.07.2011 02:00, Peter Maclean wrote:
There is no missing value nor zero values.

OK, but to say more about your problem, we need the example to be reproducible but we do not have Gdata2 available. Please see the posting guide.

Uwe Ligges




----- Original Message ----
From: Uwe Ligges<lig...@statistik.tu-dortmund.de>
To: Peter Maclean<pmaclean2...@yahoo.com>
Cc: r-help@r-project.org
Sent: Tue, July 12, 2011 2:58:10 AM
Subject: Re: [R] fitdistr() Error

Any NA values or values outside the support region of your distribution?

UWe



On 11.07.2011 23:21, Peter Maclean wrote:
I am trying to estimate a gamma function using real data and I am getting the
following error messages.
When I set a lower limit; the error message is "L-BFGS-B needs finite values
of
fn"

For other method the error message is:
Error in optim(x = c(0.105286666666667, 0.3472275, 2.057625, 0.329675,  :
     non-finite finite-difference value [1]

The codes works fine for simulated data (see below). I am using the same codes

#Grouped vector
n<- c(1:100)
yr<-c(1:100)
ny<- list(yr=yr,n=n)
require(utils)
ny<- expand.grid(ny)
y = rgamma(1000, shape=1.5, rate = 1, scale = 2)
Gdata<- cbind(ny,y)
#MLE Estimation of Gamma Distribution Parameters
library(MASS)
#Generate starting values
y<- as.numeric(Gdata2$y)
me<- mean(y)
sde<- sd(y)
sh<- sqrt(me/sde)
sc<- sqrt(sde)/me
Gdata<-split(Gdata,Gdata$n)
parm<- lapply(Gdata, function(x){
             y<- as.numeric(x$y)
             fitdistr(y ,"gamma",list(shape=sh.mom, scale=sc),
#method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN"),
             lower=0, method = c("CG"),control = list(maxit=10000))
})
parmss<-lapply(parm, function(x) x$estimate)
parmss<- t(as.data.frame(parmss))  #Estimates
parmsd<-lapply(parm, function(x) x$sd)
parmsd<- t(as.data.frame(parmsd)) #Standard errors

______________________________________________
R-help@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.


______________________________________________
R-help@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.

Reply via email to