[R] mle question

Antje Niederlein niederlein-rstat at yahoo.de
Mon Feb 7 09:17:34 CET 2011


Hello,

is there somebody who can help me with my question (see below)?

Antje


On 1 February 2011 09:09, Antje Niederlein <niederlein-rstat at yahoo.de> wrote:
> 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
>



More information about the R-help mailing list