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.