8
$\begingroup$

This is a question about the difference in calculating the null deviance in a simple Poisson model with and without an intercept.

If

y = c(2,3,6,7,8,9,10,12,15)
x = c(-1, -1, 0, 0, 0, 0, 1, 1, 1)

glm(y~x, family = poisson)

# Call:  glm(formula = y ~ x, family = poisson)
# 
# Coefficients:
# (Intercept)            x  
#      1.8893       0.6698  
# 
# Degrees of Freedom: 8 Total (i.e. Null);  7 Residual
# Null Deviance:      18.42 
# Residual Deviance: 2.939        AIC: 41.05

The null deviance can be calculated as follows:

lf = sum(y * log(y) - y - log(factorial(y)))
ln = sum(y * log(mean(y)) - mean(y) - log(factorial(y)))

2*(lf - ln)

# [1] 18.42061

If I fit the model without intercept:

glm(y~x - 1, family = poisson)

# Call:  glm(formula = y ~ x - 1, family = poisson)
# 
# Coefficients:
#     x  
# 2.373  
# 
# Degrees of Freedom: 9 Total (i.e. Null);  8 Residual
# Null Deviance:      191.9 
# Residual Deviance: 94.74        AIC: 130.9

The null deviance is now 191.9.

Can someone tell me how to calculate the null deviance for this model - I was under the impression that it would be the same as for the intercept model, i.e. a single parameter equal to the mean, but obviously it is not.

I presume I've incorrectly assumed that the null model is the same in both cases. Is it not or am I making a stupid mistake? I'd actually never considered this case before in any detail and there is obviously a gap in my knowledge somewhere.

I can get the null deviance as follows:

glm(y~1-1, family=poisson)

# Call:  glm(formula = y ~ 1 - 1, family = poisson)
# 
# No coefficients
# 
# Degrees of Freedom: 9 Total (i.e. Null);  9 Residual
# Null Deviance:      191.9
# Residual Deviance: 191.9        AIC: 226

but I don't know what this model is.

Apologies if this has been answered before but the only similar question I have seen (Why does the null deviance in glm.nb differ between models of the same response variable?) does not give an explicit explanation.

$\endgroup$
4
  • 3
    $\begingroup$ It looks to me like the null model considered in the last case is a Poisson distribution with mean 0. $\endgroup$
    – jbaums
    Commented Mar 2, 2015 at 23:22
  • $\begingroup$ @jbaums Perhaps you could write that as a brief answer? $\endgroup$
    – Glen_b
    Commented Mar 2, 2015 at 23:37
  • 2
    $\begingroup$ @jbaums, wouldn't it be mean 1 (ie, log(1) = 0)? $\endgroup$ Commented Mar 2, 2015 at 23:45
  • $\begingroup$ @gung - yes that makes sense. $\endgroup$
    – jbaums
    Commented Mar 2, 2015 at 23:48

1 Answer 1

5
$\begingroup$

Thanks to @jbaums.

y = c(2,3,6,7,8,9,10,12,15)
x = c(-1, -1, 0, 0, 0, 0, 1, 1, 1)

For the no intercept null model we have: $$ Y \sim {\rm Poisson}(1) $$ leading to the following null model likelihood term: $$ \mathcal L(y) = \exp(-1)/y! $$ or loglikelihood term: $$ l(y) = -1 - \log(y!) $$ The log-likehood for the null model is then the sum of these terms:

lnull = sum(-1 - log(factorial(y))) 

As usual the log-likelhood for the saturated model is:

lf = sum(y * log(y) - y - log(factorial(y))) 

so the null deviance is:

2*(lf - lnull) 
# [1] 191.8602 
$\endgroup$
1
  • $\begingroup$ No, you had the basic idea right, @jbaums, it was just a detail. $\endgroup$ Commented Mar 3, 2015 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.