[R] likelihood ratio test between glmer and glm

hadley wickham h.wickham at gmail.com
Mon Mar 15 01:12:30 CET 2010


> Based on a discussion found on the R mailing list but dating back to 2008, I have compared the log-likelihoods of the glm model and of the glmer model as follows:
>
> lrt <- function (obj1, obj2){
> L0 <- logLik(obj1)
> L1 <- logLik(obj2)
> L01 <- as.vector(- 2 * (L0 - L1))
> df <- attr(L1, "df") - attr(L0, "df")
> list(L01 = L01, df = df, "p-value" = pchisq(L01, df, lower.tail = FALSE)) }
>
> gm0 <- glm(cbind(female,male)~date,family = binomial, data = liz3)
> gm1 <- glmer(cbind(female,male)~date+(1|dam),family=binomial,data= liz3)
>
> lrt(gm0, gm1)

It is _very_ dangerous to do this as the likelihoods are unlikely to
be comparable/compatible.

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list