Hello,

I tried to use mle to fit a distribution(zero-inflated negbin for
count data). My call is very simple:

mle(ll)

ll() takes the three parameters, I'd like to be estimated (size, mu
and prob). But within the ll() function I have to judge if the current
parameter-set gives a nice fit or not. So I have to apply them to
observation data. But how does the method know about my observed data?
The mle()-examples define this data outside of this method and it
works. For a simple example, it was fine but when it comes to a loop
(tapply) providing different sets of observation data, it doesn't work
anymore. I'm confused - is there any way to do better?

Here is a little example which show my problem:

# R-code ---------------------------------

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 <- mle(ll)
        
        coef(fit)
        })

Can anybody help?

Antje

______________________________________________
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