Antje Niederlein <niederlein-rstat <at> yahoo.de> writes: > > A few day ago, I was looking for an answer to my question but didn't > get one. Anybody who can help now? > > Hello, > > I tried to use mle to fit a distribution(zero-inflated negbin for > count data). My call is very simple: >
I will point out that this is one of the reasons I wrote mle2 (in the bbmle package), which differs from mle in taking an explicit 'data' argument. I *think* the following does what you want (although I admit I haven't looked at the output closely): library(plyr) library(bbmle) lambda.data <- runif(10,0.5,10) ll <- function(lambda = 1) { cat("x in ll()",x,"\n") y.fit <- dpois(x, lambda) sum( (y - y.fit)^2 ) } lapply(1:10, FUN = function(x){ raw.data <- rpois(100,lambda.data[x]) freqTab <- count(raw.data) x <- freqTab$x y <- freqTab$freq / sum(freqTab$freq) cat("x in lapply", x,"\n") fit <- mle2(ll,data=data.frame(x,y)) coef(fit) }) ______________________________________________ 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.