[R] A question about loglik in GLMM

Freddy Hernández fhernanb at gmail.com
Thu Mar 15 13:22:14 CET 2012

Hi All,

I am using the glmer function to adjust a simple model (mod1) with Poisson
response variable and random intercept.  When I use logLik(mod1) I obtain a
value different from if I calculate the log-likelihood using the pdf. 
Someone could explain if I have an error?

This is the code for the example:
sigma <- 5
x1 <- rnorm(n=15)
u  <- rnorm(n=5,mean=0,sd=sigma)
mu <- exp( -1.5 + 2 * x1 + rep(u,each=3) )
y <- rpois(n=15,lambda=mu)
grupo <- rep(1:5,each=3)
#! The mod is
mod1 <- glmer(y~x1+(1|grupo),family=poisson(link = "log"),nAGQ=20)
#! loglik for mod1 using logLik function
#! loglik for mod1 again but using the pdf
sum( dpois(x=y,lambda=exp(mod1 en eta),log=TRUE) )

When sigma=0 the obtain results match.

View this message in context: http://r.789695.n4.nabble.com/A-question-about-loglik-in-GLMM-tp4474739p4474739.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list