32
$\begingroup$

I want to perform logistic regression with the following binomial response and with $X_1$ and $X_2$ as my predictors.

enter image description here

I can present the same data as Bernoulli responses in the following format.

enter image description here

The logistic regression outputs for these 2 data sets are mostly the same. The deviance residuals and AIC are different. (The difference between the null deviance and the residual deviance is the same in both cases - 0.228.)

The following are the regression outputs from R. The data sets are called binom.data and bern.data.

Here is the binomial output.

Call:
glm(formula = cbind(Successes, Trials - Successes) ~ X1 + X2, 
    family = binomial, data = binom.data)

Deviance Residuals: 
[1]  0  0  0

Coefficients:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  -2.9649    21.6072  -0.137    0.891
X1Yes        -0.1897     2.5290  -0.075    0.940
X2            0.3596     1.9094   0.188    0.851

(Dispersion parameter for binomial family taken to be 1)

Null deviance:  2.2846e-01  on 2  degrees of freedom
Residual deviance: -4.9328e-32  on 0  degrees of freedom
AIC: 11.473

Number of Fisher Scoring iterations: 4

Here is the Bernoulli output.

Call:
glm(formula = Success ~ X1 + X2, family = binomial, data = bern.data)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.6651  -1.3537   0.7585   0.9281   1.0108  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  -2.9649    21.6072  -0.137    0.891
X1Yes        -0.1897     2.5290  -0.075    0.940
X2            0.3596     1.9094   0.188    0.851

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 15.276  on 11  degrees of freedom
Residual deviance: 15.048  on  9  degrees of freedom
AIC: 21.048

Number of Fisher Scoring iterations: 4

My questions:

1) I can see that the point estimates and standard errors between the 2 approaches are equivalent in this particular case. Is this equivalence true in general?

2) How can the answer for Question #1 be justified mathematically?

3) Why are the deviance residuals and AIC different?

$\endgroup$
24
$\begingroup$

1) Yes. You can aggregate/de-aggregate (?) binomial data from individuals with the same covariates. This comes from the fact that the sufficient statistic for a binomial model is the total number of events for each covariate vector; and the Bernoulli is just a special case of the binomial. Intuitively, each Bernoulli trial that makes up a binomial outcome is independent, so there shouldn't be a difference between counting these as a single outcome or as separate individual trials.

2) Say we have $n$ unique covariate vectors $x_1, x_2, \ldots, x_n$, each of which has a binomial outcome on $N_i$ trials, i.e. $$Y_i \sim \mathrm{Bin}(N_i, p_i)$$ You've specified a logistic regression model, so $$\mathrm{logit}(p_i) = \sum_{k=1}^K \beta_k x_{ik}$$ although we'll see later that this isn't important.

The log-likelihood for this model is $$\ell(\beta; Y) = \sum_{i=1}^n \log {N_i \choose Y_i} + Y_i \log(p_i) + (N_i - Y_i) \log(1-p_i)$$ and we maximise this with respect to $\beta$ (in the $p_i$ terms) to get our parameter estimates.

Now, consider that for each $i = 1, \ldots, n$, we split the binomial outcome into $N_i$ individual Bernoulli/binary outcomes, as you have done. Specifically, create $$Z_{i1}, \ldots, Z_{iY_i} = 1$$ $$Z_{i(Y_i+1)}, \ldots, Z_{iN_i} = 0$$ That is, the first $Y_i$ are 1s and the rest are 0s. This is exactly what you did - but you could equally have done the first $(N_i - Y_i)$ as 0s and the rest as 1s, or any other ordering, right?

Your second model says that $$Z_{ij} \sim \mathrm{Bernoulli}(p_i)$$ with the same regression model for $p_i$ as above. The log-likelihood for this model is $$ \ell(\beta; Z) = \sum_{i=1}^n \sum_{j=1}^{N_i} Z_{ij}\log(p_i) + (1-Z_{ij})\log(1-p_i) $$ and because of the way we defined our $Z_{ij}$s, this can be simplified to $$ \ell(\beta; Y) = \sum_{i=1}^n Y_i \log(p_i) + (N_i - Y_i)\log(1-p_i) $$ which should look pretty familiar.

To get the estimates in the second model, we maximise this with respect to $\beta$. The only difference between this and the first log-likelihood is the term $\log {N_i \choose Y_i}$, which is constant with respect to $\beta$, and so doesn't affect the maximisation and we'll get the same estimates.

3) Each observation has a deviance residual. In the binomial model, they are $$ D_i = 2\left[Y_i \log \left( \frac{Y_i/N_i}{\hat{p}_i} \right) + (N_i-Y_i) \log \left( \frac{1-Y_i/N_i}{1-\hat{p}_i} \right)\right] $$ where $\hat{p}_i$ is the estimated probability from your model. Note that your binomial model is saturated (0 residual degrees of freedom) and has perfect fit: $\hat{p}_i = Y_i/N_i$ for all observations, so $D_i = 0$ for all $i$.

In the Bernoulli model, $$ D_{ij} = 2\left[Z_{ij} \log \left( \frac{Z_{ij}}{\hat{p}_i} \right) + (1-Z_{ij}) \log \left(\frac{1-Z_{ij}}{1-\hat{p}_i} \right)\right] $$ Apart from the fact that you will now have $\sum_{i=1}^n N_i$ deviance residuals (instead of $n$ as with the binomial data), these will each be either $$D_{ij} = -2\log(\hat{p}_i)$$ or $$D_{ij} = -2\log(1-\hat{p}_i)$$ depending on whether $Z_{ij} = 1$ or $0$, and are obviously not the same as the above. Even if you sum these over $j$ to get a sum of deviance residuals for each $i$, you don't get the same: $$ D_i = \sum_{j=1}^{N_i} D_{ij} = 2\left[Y_i \log \left( \frac{1}{\hat{p}_i} \right) + (N_i-Y_i) \log \left( \frac{1}{1-\hat{p}_i} \right)\right] $$

The fact that the AIC is different (but the change in deviance is not) comes back to the constant term that was the difference between the log-likelihoods of the two models. When calculating the deviance, this is cancelled out because it is the same in all models based on the same data. The AIC is defined as $$AIC = 2K - 2\ell$$ and that combinatorial term is the difference between the $\ell$s:

$$AIC_{\mathrm{Bernoulli}} - AIC_{\mathrm{Binomial}} = 2\sum_{i=1}^n \log {N_i \choose Y_i} = 9.575$$

$\endgroup$
  • $\begingroup$ Thanks for your very detailed reply, Mark! Sorry for the delay in my response - I was on vacation. 3) Given that the 2 models give different results for deviance residuals and AIC, which one is correct or better? a) As I understand, observations with a deviance residual in excess of two may indicate lack of fit, so the absolute values of the deviance residuals matter. b) Since AIC is used to compare the fit between different models, perhaps there is no "correct" AIC. I would just compare the AICs of 2 binomial models or 2 Bernoulli models. $\endgroup$ – A Scientist Apr 11 '15 at 4:52
  • $\begingroup$ a) For the binary data, the $D_{ij}$ will be > 2 if either ($Z_{ij} = 1$ and $\hat{p}_i < e^{-1} = 0.368$) or ($Z_{ij} = 0$ and $\hat{p}_i > 1 - e^{-1} = 0.632$). So even if your model fits the binomial data perfectly for the $i$th covariate vector (i.e. $Y_i / N_i = \hat{p}_i < 0.368$, say), then the $Y_i$ $Z_{ij}$s that you've arbitrarily allocated as being 1 will have $D_{ij} > 2$. For this reason, I think the deviance residuals make more sense with the binomial data. Furthermore, the deviance itself for binary data does not have its usual properties... $\endgroup$ – Mark Apr 12 '15 at 23:25
  • $\begingroup$ ...Link to further info about that last statement $\endgroup$ – Mark Apr 12 '15 at 23:25
  • 1
    $\begingroup$ b) Yes, comparing $AIC$s between models only makes sense when the data used to fit each model is exactly the same. So compare Bernoulli with Bernoulli or binomial with binomial. $\endgroup$ – Mark Apr 12 '15 at 23:28
  • $\begingroup$ Thanks, Mark! Your thoughtful and detailed replies are much appreciated! $\endgroup$ – A Scientist Apr 15 '15 at 2:52
0
$\begingroup$

I just want make comments on the last paragraph, “The fact that the AIC is different (but the change in deviance is not) comes back to the constant term that was the difference between the log-likelihoods of the two models. When calculating the change in deviance, this is cancelled out because it is the same in all models based on the same data." Unfortunately, this is not correct for the change in deviance. The deviance does not include the constant term Ex (extra constant term in the log-likelihood for the binomial data). Therefore, the change in deviance does nothing to do with the constant term EX. The deviance compares a given model to the full model. The fact that the deviances are different from Bernoulli/binary and binomial modelling but change in deviance is not is due to the difference in the full model log-likelihood values. These values are cancelled out in calculating the deviance changes. Therefore, Bernoulli and binomial logistic regression models yield an identical deviance changes provided the predicted probabilities pij and pi are the same. In fact, that is true for the probit and other link functions.

Let lBm and lBf denote the log-likelihood values from fitting model m and full model f to Bernoulli data. The deviance is then

    DB=2(lBf - lBm)=-2(lBm – lBf).

Although the lBf is zero for the binary data, we have not simplified the DB and kept it as is. The deviance from the binomial modelling with the same covariates is

    Db=2(lbf+Ex – (lbm+Ex))=2(lbf – lbm) = -2(lbm – lbf)

where the lbf+Ex and lbm+Ex are the log-likelihood values by the full and m models fitted to the binomial data. The extra constant term (Ex) is disappeared from the right hand side of the Db. Now look at change in deviances from Model 1 to Model 2. From Bernoulli modelling, we have change in deviance of

    DBC=DB2-DB1=2(lBf – lBm2)-2(lBf – lBm1) =2(lBm1 – lBm2).

Similarly, change in deviance from binomial fitting is

    DbC=DB2-DB1=2(lbf – lbm2)-2(lbf – lbm1) =2(lbm1 – lbm2).

It is immediately follows that the deviance changes are free from the log-likelihood contributions from full models, lBf and lbf. Therefore, we will get the same change in deviance, DBC = DbC, if lBm1 = lbm1 and lBm2 = lbm2. We know that is the case here and that why we are getting the same deviance changes from Bernoulli and binomial modelling. The difference between lbf and lBf leads to the different deviances.

$\endgroup$
  • 6
    $\begingroup$ Would it be possibly for you to edit formatting of your answer? Unfortunately in this form it is not very readable. I would encourage you to brake the text in paragraphs and add $\TeX$ formatting to the formulas. It is also not always clear what does the abbreviations you use mean. $\endgroup$ – Tim Apr 6 '16 at 14:30
  • $\begingroup$ Many thanks, Tim. I am not familiar with the TEX formatting. I have originally typed in the Word, but I was unable to copy and paste. I have separated the equations from the text. $\endgroup$ – Saei Apr 6 '16 at 15:35
  • $\begingroup$ I'm not sure if you misread that paragraph: I said "the AIC is different (but the change in deviance is not)", and the remainder of the paragraph explains why the AIC is different between the two models. I didn't claim that the change in deviance depended on the constant term. In fact, I said "When calculating the change in deviance, this [the constant term] is cancelled out because it is the same in all models based on the same data" $\endgroup$ – Mark Apr 6 '16 at 22:02
  • $\begingroup$ The problem is that there is only one “constant term” in the text and it is the combinatorial term (binomial coefficient). When you say "this" is cancelled out, it implies that the constant term is included in the deviance. The difference between deviances from the Bernoulli and binomial models is the contributions from the log-likelihood value lbf from full the model. The lbf does not vary by different binomial models on the same data and it is cancelled out when calculating the change in deviance. $\endgroup$ – Saei Apr 7 '16 at 8:14
  • $\begingroup$ Ah ok I see what you mean. I have edited my answer accordingly, leaving in the reference to the change in deviance because the asker specifically mentioned it. The change in deviance is the same because the deviance doesn't depend on the constant term. $\endgroup$ – Mark Apr 7 '16 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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