Thanks a lot to everybody who answered! Sorry for not mentioning the package I used (I am aware of this fact but I simply forgot to put it to the example code....) Thanks a lot for explaning the problem to me. I was pretty sure that it ist something like this but I thought, I've made a mistake in how to use mle() correctly. I think, I'll look into Bens mle2() method and figure out whether this is a more elegant way :-)
Ciao, Antje On 7 February 2011 21:39, Ben Bolker <bbol...@gmail.com> wrote: > 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. > ______________________________________________ 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.