[R-sig-ME] Deviance residuals don't sum up to deviance

Steve Walker steve.walker at utoronto.ca
Fri Aug 22 16:09:45 CEST 2014


I just remembered that this bug is actually fixed in the development 
version of lme4 on github,

 > gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
+ data = cbpp, family = binomial)
 > deviance(gm1)
[1] 73.47428
 > sum(residuals(gm1, type= "deviance")^2)
[1] 73.47428

So this will be fixed in the next lme4 release to CRAN.

Cheers,
Steve



On 2014-08-22, 9:49 AM, Steve Walker wrote:
> Does this document by Ben Bolker clear it up?
>
> https://github.com/lme4/lme4/blob/master/misc/notes/deviance.rmd
>
> Steve
>
> On 2014-08-22, 9:07 AM, Roelof Coster wrote:
>> Thanks for the suggestion!
>>
>> I can use the example which you suggest:
>>
>>> gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
>> data = cbpp, family = binomial)
>>> deviance(gm1)
>> [1] 184.0531
>>> sum(residuals(gm1, type= "deviance")^2)
>> [1] 73.47428
>>
>> So here is what I don't understand: these deviance residuals, squared,
>> don't add up to the total deviance as I expected they would.
>>
>> Best regards, Roelof Coster
>>
>>
>>
>>
>> 2014-08-22 13:58 GMT+02:00 Martin Maechler <maechler at stat.math.ethz.ch>:
>>
>>>
>>>> Hello,
>>>> I fitted a logistic regression model with glmer. In the resulting
>>>> model,
>>>> the reported deviance is not the same as the sum of the squares of the
>>>> residual deviances. The deviance is 3909, the sum of square deviance
>>>> residuals is 3747.
>>>
>>>> These two should be equal, shouldn't they? The difference seems too
>>>> large
>>>> for a roundoff error, I think.
>>>
>>>> My data are 150k observations and the fitted probabilities are
>>>> generally
>>>> very small (between 1e-7 and 1e-2, median 1e-4).
>>>
>>> Can you at least show the exact R function calls that you did to
>>> produce it?  Even better,
>>> can you please use the 'gm1' from the first example in
>>> help(glmer),
>>>
>>>    (gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 |
>>> herd),
>>>                  data = cbpp, family = binomial))
>>>
>>> and now show how you compute these to sums with *reproducible* R
>>> code.  That way we (the readers of R-SIG-ME) can be motivated
>>> much more to help you.
>>>
>>>
>>>> Thanks! Roelof Coster
>>>
>>> You are welcome ;-)
>>> Martin Maechler
>>>
>>
>>     [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-mixed-models at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
>>
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
>



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