[R-sig-ME] Variance explained by random factor

hadley wickham h.wickham at gmail.com
Tue Aug 26 03:34:12 CEST 2008


On Thu, Aug 14, 2008 at 4:43 AM, Douglas Bates <bates at stat.wisc.edu> wrote:
> On Thu, Aug 14, 2008 at 11:24 AM, Renwick, A. R. <a.renwick at abdn.ac.uk> wrote:
>> Many apologise but the glm model I compared was ma not ma1 and thus did have the interaction term:
>
>> ma<-glm(RoundedOverlap~sess+breedfem+sess:breedfem ,family=poisson,data=Male)
>> mixed<-lmer(RoundedOverlap~sess+breedfem+sess:breedfem+(1|Site),family=poisson,data=Male)
>
> In that case it could be that the deviance or log-likelihood is not
> being evaluated correctly in glmer.  Look at the slot named 'deviance'
> in the lmer fit.  It should be a named numeric vector.  The names of
> interest are 'disc', the discrepancy for the generalized linear models
> (this is the deviance without the compensation for the null deviance),
> 'ldL2', the logarithm of the square of the determinant of the Cholesky
> factor of a second-order term, and usqr, the squared length of the
> transformed random effects.  For a mixed-effects model in which the
> variance of the random effects is estimated as zero, both 'ldL2' and
> 'usqr' should be zero.
>
> You can check these values in
>
> mixed at deviance

But isn't possible that the log-likelihoods are incompatible between
glm and glmer?  Maybe one chose to drop an irrelevant constant and the
other didn't.

lmer currently doesn't let you specify a model without a random
effect, but I think this gets pretty close:

counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
fixed <- rep(1, 9)
d.AD <- data.frame(treatment, outcome, counts)

m_glm <- glm(counts ~ outcome, family = poisson)
m_lmer <- glmer(counts ~ outcome + (1 | fixed), family = poisson)

> logLik(m_glm)
'log Lik.' -23.38066 (df=3)
> logLik(m_lmer)
'log Lik.' -2.564571 (df=4)

Although they do have the same deviance:

> deviance(m_lmer)
      ML
5.129141
> deviance(m_glm)
[1] 5.129141


Hadley

-- 
http://had.co.nz/




More information about the R-sig-mixed-models mailing list