11.2 Maximum likelihood estimation

Data are often grouped: at the \(i\)th setting \(\mathbf {x}_i\) of the regressors there are \(m_i\) trials, of which \(y_i\) are successes, so \(y_i \sim \text {Bin}(m_i, \pi _i)\), \(i = 1, \dots , n\), independently. (Ungrouped binary data are the case \(m_i = 1\).) The log-likelihood is, apart from a constant \(\sum \log \binom {m_i}{y_i}\) that does not involve \(\boldsymbol \beta \), \begin {align*} \ell (\boldsymbol \beta ) &= \sum _{i=1}^n\bigl [y_i\log \pi _i + (m_i - y_i)\log (1 - \pi _i)\bigr ] \\ &= \sum _{i=1}^n\Bigl [y_i\log \frac {\pi _i}{1 - \pi _i} + m_i\log (1 - \pi _i)\Bigr ] . \end {align*}

With \(\eta _i = \log \{\pi _i/(1 - \pi _i)\} = \mathbf {x}_i^\top \boldsymbol \beta \) and \(1 - \pi _i = 1/(1 + e^{\eta _i})\), this is \[ \ell (\boldsymbol \beta ) = \sum _{i=1}^n\bigl [y_i\eta _i - m_i\log (1 + e^{\eta _i})\bigr ] . \]

Theorem 11.2.1. Let \(\boldsymbol \mu \) have components \(\mu _i = m_i\pi _i\), and let \(\mathbf {W} = \operatorname {diag}(w_i)\) with \(w_i = m_i\pi _i(1 - \pi _i)\). Then

(i)
the gradient (the score) of \(\ell \) is \(\mathbf {U}(\boldsymbol \beta ) = \mathbf {X}^\top (\mathbf {y} - \boldsymbol \mu )\), so the maximum-likelihood estimate satisfies the likelihood equations \(\mathbf {X}^\top \mathbf {y} = \mathbf {X}^\top \hat {\boldsymbol \mu }\);
(ii)
the matrix of second derivatives is \(-\mathbf {X}^\top \mathbf {WX}\), which does not involve \(\mathbf {y}\);
(iii)
if \(\mathbf {X}\) has full column rank, \(\ell \) is strictly concave, so it has at most one maximum, and any solution of the likelihood equations is the maximum-likelihood estimate.

Proof. (i) \(\dfrac {d}{d\eta }\log (1 + e^{\eta }) = \dfrac {e^{\eta }}{1 + e^{\eta }} = \pi \), so \(\partial \ell /\partial \eta _i = y_i - m_i\pi _i = y_i - \mu _i\), and since \(\partial \eta _i/\partial \beta _j = x_{ij}\), the chain rule gives \(\partial \ell /\partial \beta _j = \sum _i x_{ij}(y_i - \mu _i)\).

(ii) \(d\pi /d\eta = e^{\eta }/(1 + e^{\eta })^2 = \pi (1 - \pi )\), so \(\partial \mu _i/\partial \beta _l = m_i\pi _i(1 - \pi _i)x_{il} = w_ix_{il}\), and \(\partial ^2\ell /\partial \beta _j\partial \beta _l = -\sum _i x_{ij}w_ix_{il}\), the \((j, l)\) element of \(-\mathbf {X}^\top \mathbf {WX}\).

(iii) For \(\mathbf {v} \ne \mathbf {0}\), \(\mathbf {v}^\top \mathbf {X}^\top \mathbf {WXv} = \sum _i w_i(\mathbf {x}_i^\top \mathbf {v})^2 > 0\), because every \(w_i > 0\) and \(\mathbf {Xv} \ne \mathbf {0}\). So the second-derivative matrix is negative definite everywhere, and \(\ell \) is strictly concave: along any line it is a function with negative second derivative, so a point with zero gradient is the unique maximum. □

When the model contains an intercept, the first likelihood equation reads \(\sum y_i = \sum \hat \mu _i\): the fitted number of successes equals the observed number, as the sum of the residuals is zero in least squares.

The likelihood equations are non-linear in \(\boldsymbol \beta \), and in general they must be solved by iteration. Newton’s method turns out to be a sequence of weighted least squares fits.

Theorem 11.2.2 (Iteratively reweighted least squares). Newton’s method for maximising \(\ell \), started from \(\boldsymbol \beta ^{(t)}\), gives \[ \boldsymbol \beta ^{(t+1)} = (\mathbf {X}^\top \mathbf {WX})^{-1}\mathbf {X}^\top \mathbf {Wz} , \qquad z_i = \eta _i + \frac {y_i - \mu _i}{w_i} , \] where \(\eta _i\), \(\mu _i\), \(w_i\) are evaluated at \(\boldsymbol \beta ^{(t)}\). That is, each step is the weighted least squares regression of the working response \(\mathbf {z}\) on \(\mathbf {X}\) with weights \(w_i\).

Proof. Newton’s method maximises the second-order Taylor approximation of \(\ell \) at \(\boldsymbol \beta ^{(t)}\). By Theorem 11.2.1 this gives \[ \boldsymbol \beta ^{(t+1)} = \boldsymbol \beta ^{(t)} + (\mathbf {X}^\top \mathbf {WX})^{-1}\mathbf {U} . \] Since \(\mathbf {X}\boldsymbol \beta ^{(t)} = \boldsymbol \eta \) and \(\mathbf {y} - \boldsymbol \mu = \mathbf {W}(\mathbf {z} - \boldsymbol \eta )\), \begin {align*} \boldsymbol \beta ^{(t+1)} &= (\mathbf {X}^\top \mathbf {WX})^{-1}\bigl [\mathbf {X}^\top \mathbf {WX}\boldsymbol \beta ^{(t)} + \mathbf {X}^\top \mathbf {W}(\mathbf {z} - \boldsymbol \eta )\bigr ] \\ &= (\mathbf {X}^\top \mathbf {WX})^{-1}\mathbf {X}^\top \mathbf {Wz} . \end {align*}

This is the weighted least squares estimate of Theorem 6.4.1 with response \(\mathbf {z}\). □

The working response \(z_i\) is a linearised version of the logit of \(y_i/m_i\), and \(w_i = m_i\pi _i(1 - \pi _i)\) is the reciprocal of its approximate variance, so the weighting is exactly the remedy of Section 6 for unequal variances, with the weights recomputed as the estimates improve. A common start is \(\boldsymbol \beta = \mathbf {0}\), which gives \(\pi _i = \frac 12\). The iteration usually converges in a handful of steps. It fails only when the estimate does not exist: if some combination of the regressors separates the successes from the failures completely, the likelihood keeps increasing as the coefficients go to infinity.

Example 11.2.3. Batches of \(20\) insects were exposed to five doses of an insecticide, and the numbers killed were:

Dose, \(x\) 1 2 3 4 5
Killed, \(y\) (of 20) 2 6 10 14 18

Fit the logistic regression of the probability of death on dose.

Solution. First step. At \(\boldsymbol \beta = \mathbf {0}\), every \(\pi _i = \frac 12\), \(\mu _i = 10\) and \(w_i = 20 \times \frac 14 = 5\), so \(z_i = 0 + (y_i - 10)/5 = -1.6, -0.8, 0, 0.8, 1.6\). The weights are equal, so the weighted fit is the ordinary straight-line fit of \(z\) on \(x\): with \(\bar x = 3\) and \(\sum (x_i - 3)^2 = 10\), \begin {align*} \beta _1^{(1)} &= \frac {\sum (x_i - 3)z_i}{10} = \frac {3.2 + 0.8 + 0 + 0.8 + 3.2}{10} = 0.8 , \\ \beta _0^{(1)} &= \bar z - 0.8\bar x = -2.4 . \end {align*}

Further steps. Recomputing \(\pi _i\), \(w_i\) and \(z_i\) at each new estimate gives:

Step \(t\) \(\beta _0^{(t)}\) \(\beta _1^{(t)}\) \(\ell (\boldsymbol \beta ^{(t)})\)
0 0 0 \(-69.315\)
1 \(-2.4000\) \(0.8000\) \(-52.063\)
2 \(-2.9666\) \(0.9889\) \(-51.475\)
3 \(-3.0351\) \(1.0117\) \(-51.469\)
4 \(-3.0360\) \(1.0120\) \(-51.469\)

The log-likelihood rises at each step and the estimates settle after four steps: \[ \operatorname {logit}\hat \pi = -3.036 + 1.012x . \] The fitted probabilities are \(0.117, 0.267, 0.500, 0.733, 0.883\), so the fitted numbers killed are \(2.33, 5.33, 10.00, 14.67, 17.67\). They add to \(50\), the observed total, as Theorem 11.2.1 requires. The odds ratio for one unit of dose is \(e^{1.012} = 2.75\): each extra unit multiplies the odds of death by \(2.75\). Figure 23, panel 3, shows the fit.

A single indicator: the two-by-two table

With one indicator regressor, the likelihood equations can be solved exactly.

Theorem 11.2.4. Suppose \(z = 0\) for group \(0\) and \(z = 1\) for group \(1\), with \(y_0\) successes in \(m_0\) trials in group \(0\) and \(y_1\) in \(m_1\) in group \(1\), and fit \(\operatorname {logit}\pi = \beta _0 + \beta _1z\). Then \(\hat \pi _0 = y_0/m_0\), \(\hat \pi _1 = y_1/m_1\), \[ \hat \beta _0 = \log \frac {y_0}{m_0 - y_0}, \qquad \hat \beta _1 = \log \frac {y_1(m_0 - y_0)}{y_0(m_1 - y_1)} , \] so \(e^{\hat \beta _1}\) is the sample odds ratio, and the variance estimate of Theorem 11.3.1 below is \[ \widehat {\operatorname {Var}}(\hat \beta _1) = \frac {1}{y_0} + \frac {1}{m_0 - y_0} + \frac {1}{y_1} + \frac {1}{m_1 - y_1} . \]

Proof. The columns of \(\mathbf {X}\) are \(\mathbf {1}\) and \(\mathbf {z}\), so the likelihood equations say the fitted successes equal the observed ones in total and in group \(1\), hence in each group: \(m_0\hat \pi _0 = y_0\) and \(m_1\hat \pi _1 = y_1\). Taking logits, \(\hat \beta _0 = \operatorname {logit}\hat \pi _0\) and \(\hat \beta _0 + \hat \beta _1 = \operatorname {logit}\hat \pi _1\), which give the formulas. For the variance, with \(w_g = m_g\hat \pi _g(1 - \hat \pi _g)\), \begin {align*} \mathbf {X}^\top \mathbf {WX} &= \begin {pmatrix} w_0 + w_1 & w_1 \\ w_1 & w_1 \end {pmatrix} , \\ \bigl [(\mathbf {X}^\top \mathbf {WX})^{-1}\bigr ]_{22} &= \frac {w_0 + w_1}{w_0w_1} = \frac {1}{w_0} + \frac {1}{w_1} , \end {align*}

and \(\dfrac {1}{w_g} = \dfrac {1}{m_g\hat \pi _g(1 - \hat \pi _g)} = \dfrac {1}{m_g\hat \pi _g} + \dfrac {1}{m_g(1 - \hat \pi _g)} = \dfrac {1}{y_g} + \dfrac {1}{m_g - y_g}\). □

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.