deviance() 函数 returns 奇数

deviance() function returns odd value

参见下面的示例代码:

library(lme4)
M100 <- glmer(vs ~ wt + (1|cyl), data=mtcars, family=binomial("logit"))
deviance(M100)
summary(M100)$AICtab["deviance"]

偏差函数 returns 13.95 但从模型汇总对象读取偏差 returns 24.76。这是怎么回事?

这不是错误;你看到了偏差的不同定义之间的区别。 deviance(M100) 给出相对的、有条件的偏差,而 summary(M100)$AICtab["deviance"](也等于 -2*logLik(M100))给出绝对的、无条件的偏差 [定义见下文]。

改在NEWS for 1.1-8中引用为

deviance() now returns the deviance, rather than half the negative log-likelihood, for GLMMs fitted with Laplace (the behaviour for LMMs and GLMMs fitted with nAGQ>1 has not changed)

?deviance.merMod的详细信息部分有很多信息:

Deviance and log-likelihood of GLMMs:

One must be careful when defining the deviance of a GLM. For example, should the deviance be defined as minus twice the log-likelihood or does it involve subtracting the deviance for a saturated model? To distinguish these two possibilities we refer to absolute deviance (minus twice the log-likelihood) and relative deviance (relative to a saturated model, e.g. Section 2.3.1 in McCullagh and Nelder 1989). With GLMMs however, there is an additional complication involving the distinction between the likelihood and the conditional likelihood. The latter is the likelihood obtained by conditioning on the estimates of the conditional modes of the spherical random effects coefficients, whereas the likelihood itself (i.e. the unconditional likelihood) involves integrating out these coefficients. The following table summarizes how to extract the various types of deviance for a ‘glmerMod’ object.

                     conditional        unconditional 
   relative   ‘deviance(object)’         NA in ‘lme4’ 
   absolute  ‘object@resp$aic()’  ‘-2*logLik(object)’ 

[caveats abridged]

For more information about this topic see the ‘misc/logLikGLMM’ directory in the package source.