Tutorials › Generalized Linear Models › Worked Score Derivations Across Three GLM Families

Likelihood Scores and Equations · Tutorial 178 of 981

Worked Score Derivations Across Three GLM Families

Follow the likelihood derivatives in three GLM families and verify the coefficient equations directly from observed and fitted means.

Intermediate 11 min read

What You'll Learn

  • Derive coefficient scores for Gaussian identity, Bernoulli logit, and Poisson log-link models
  • Distinguish response residuals from fitted means in each score equation
  • Check fitted coefficient equations using explicit numerical examples
  • Interpret the score equations as covariate-weighted residual constraints
  • Recognize why an intercept makes the residuals sum to zero
  • Avoid treating a vanishing score as proof of a unique finite maximum

From Likelihood Derivatives to Fitted Residuals

A coefficient score is the derivative of the log-likelihood with respect to a regression coefficient. In a GLM, differentiating first with respect to the linear predictor and then applying the chain rule gives a direct connection between the score and the difference between each observed response and its fitted mean. This tutorial works out that connection for three common models: Gaussian identity, Bernoulli logit, and Poisson log-link.

Assume independent observations \(Y_1,\ldots,Y_n\), fixed covariate vectors \(x_i\in\mathbb{R}^p\), and linear predictors \(\eta_i=x_i^\mathsf{T}\beta\), where \(\beta\in\mathbb{R}^p\). Write \(\mu_i=E[Y_i]\) for the model mean and \(\hat\mu_i\) for its fitted value at an estimated coefficient vector \(\hat\beta\). Define the response residual \(r_i=y_i-\mu_i\) at a given coefficient vector; at the fit this becomes \(y_i-\hat\mu_i\). A score equation sets each component of the likelihood gradient equal to zero.

Definition: For log-likelihood \(\ell(\beta)\), the coefficient score is the vector \(U(\beta)=\partial\ell(\beta)/\partial\beta\). A finite interior maximum of a differentiable likelihood must satisfy \(U(\hat\beta)=0\). This necessary condition alone does not establish that a maximum exists or is unique.

The calculations below use the usual maximum-likelihood convention: the Gaussian variance \(\sigma^2>0\) is common across observations, and the Bernoulli and Poisson observations have the stated distributions. The examples have finite fitted coefficient values, so the likelihood derivatives and score equations apply at their fits.

Gaussian Identity-Link Model

For independent \(Y_i\sim N(x_i^\mathsf{T}\beta,\sigma^2)\), the identity link gives \(\mu_i=\eta_i=x_i^\mathsf{T}\beta\). Treating \(\sigma^2\) as fixed, the log-likelihood, up to no omitted \(\beta\)-dependent terms, is

$$ \ell(\beta)=-\frac{n}{2}\log(2\pi\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^n(y_i-x_i^\mathsf{T}\beta)^2. $$

For coefficient \(\beta_j\), the derivative of the squared-error term is \(\partial (y_i-x_i^\mathsf{T}\beta)^2/\partial\beta_j=-2(y_i-x_i^\mathsf{T}\beta)x_{ij}\). Therefore

$$ \frac{\partial\ell}{\partial\beta_j} =\frac{1}{\sigma^2}\sum_{i=1}^n x_{ij}(y_i-\mu_i), \qquad U(\beta)=\frac{1}{\sigma^2}X^\mathsf{T}(y-X\beta). $$

Thus the fitted Gaussian coefficient equations require each covariate-weighted residual sum to be zero. The common factor \(1/\sigma^2\) does not affect their roots. Estimating a common variance as well does not change this coefficient score.

Worked Example: Gaussian Identity Regression

Take four observations with \(x_i=0,1,2,3\) and responses \(y_i=1,2,2,4\). Fit the model \(\mu_i=\beta_0+\beta_1x_i\). The means are \(\bar x=1.5\) and \(\bar y=2.25\). The least-squares slope and intercept are

$$ \hat\beta_1= \frac{\sum_i(x_i-\bar x)(y_i-\bar y)}{\sum_i(x_i-\bar x)^2} =\frac{4.5}{5}=0.9, \qquad \hat\beta_0=\bar y-\hat\beta_1\bar x=2.25-(0.9)(1.5)=0.9. $$

The fitted means are \(0.9,1.8,2.7,3.6\), so the residuals \(y_i-\hat\mu_i\) are \(0.1,0.2,-0.7,0.4\). Check the intercept score and slope score separately:

$$ \sum_i(y_i-\hat\mu_i)=0.1+0.2-0.7+0.4=0, \qquad \sum_i x_i(y_i-\hat\mu_i)=0(0.1)+1(0.2)+2(-0.7)+3(0.4)=0. $$

Both coefficient scores are zero; the Gaussian score components are these sums divided by \(\sigma^2\). This checks the likelihood equations directly, not just the reported coefficient values.

Bernoulli Logit Model

For independent \(Y_i\sim\operatorname{Bernoulli}(p_i)\), the logit link specifies \(\log\{p_i/(1-p_i)\}=\eta_i=x_i^\mathsf{T}\beta\). Equivalently, \(p_i=e^{\eta_i}/(1+e^{\eta_i})\). The log-likelihood is

$$ \ell(\beta)=\sum_{i=1}^n\{y_i\log p_i+(1-y_i)\log(1-p_i)\}. $$

To differentiate, note that \(dp_i/d\eta_i=p_i(1-p_i)\). The derivative of an observation's log-likelihood with respect to \(\eta_i\) is

$$ \left(\frac{y_i}{p_i}-\frac{1-y_i}{1-p_i}\right)p_i(1-p_i) =y_i(1-p_i)-(1-y_i)p_i =y_i-p_i. $$

Since \(\partial\eta_i/\partial\beta_j=x_{ij}\), the chain rule yields \(U_j(\beta)=\sum_i x_{ij}(y_i-p_i)\). In vector form, \(U(\beta)=X^\mathsf{T}(y-p)\). Here the response residual is \(y_i-p_i\), not a difference between \(y_i\) and the linear predictor.

Worked Example: Bernoulli Logit With Two Groups

Use an intercept and a group indicator \(x_i\), equal to 0 for three observations with outcomes \(1,0,0\), and equal to 1 for four observations with outcomes \(1,1,0,1\). The model has \(\eta_i=\beta_0+\beta_1x_i\). The observed success proportions are \(1/3\) in group 0 and \(3/4\) in group 1. The fitted parameters matching these proportions are

$$ \hat\beta_0=\log\frac{1/3}{2/3}=-\log 2, \qquad \hat\beta_1=\log\frac{3/4}{1/4}-\hat\beta_0=\log 3+\log 2=\log 6. $$

These coefficients give fitted probabilities \(1/3\) for group 0 and \(\operatorname{logit}^{-1}(-\log2+\log6)=\operatorname{logit}^{-1}(\log3)=3/4\) for group 1. In group 0, residuals are \(2/3,-1/3,-1/3\), whose sum is zero. In group 1, residuals are \(1/4,1/4,-3/4,1/4\), also summing to zero. Consequently,

$$ U_0=\sum_i(y_i-\hat p_i)=0, \qquad U_1=\sum_i x_i(y_i-\hat p_i) =\sum_{i:x_i=1}(y_i-\hat p_i)=0. $$

The intercept score checks the total residual, while the group-indicator score checks the residual total in group 1. Together they verify both coefficient equations.

Poisson Log-Link Model

For independent \(Y_i\sim\operatorname{Poisson}(\mu_i)\), the log link gives \(\log\mu_i=\eta_i=x_i^\mathsf{T}\beta\), so \(\mu_i=e^{\eta_i}\). The log-likelihood is

$$ \ell(\beta)=\sum_{i=1}^n\{y_i\eta_i-e^{\eta_i}-\log(y_i!)\}. $$

The factorial term does not depend on \(\beta\). Differentiating the remaining terms first with respect to \(\eta_i\) gives \(y_i-e^{\eta_i}=y_i-\mu_i\); applying the chain rule gives

$$ U_j(\beta)=\sum_{i=1}^n x_{ij}(y_i-\mu_i), \qquad U(\beta)=X^\mathsf{T}(y-\mu). $$

As in the logit model, each coefficient score is a covariate-weighted sum of response residuals, but the fitted mean is now \(e^{x_i^\mathsf{T}\beta}\).

Worked Example: Poisson Log-Link With Two Groups

Let \(x_i=0\) for counts \(0,1,2\), and \(x_i=1\) for counts \(1,2,3,2\). The group mean counts are \(1\) and \(2\). Under \(\log\mu_i=\beta_0+\beta_1x_i\), the fitted coefficients are

$$ \hat\beta_0=\log(1)=0, \qquad \hat\beta_1=\log(2)-\hat\beta_0=\log2. $$

Thus fitted means are 1 for every group-0 observation and 2 for every group-1 observation. The residuals are \(-1,0,1\) in group 0 and \(-1,0,1,0\) in group 1. Their group totals are both zero, so

$$ U_0=\sum_i(y_i-\hat\mu_i)=(-1+0+1)+(-1+0+1+0)=0, \qquad U_1=\sum_i x_i(y_i-\hat\mu_i)=-1+0+1+0=0. $$

The zero intercept score and zero group-indicator score confirm the fitted Poisson coefficient equations.

What the Residual Checks Establish

The three models have different likelihoods and fitted mean functions, but their coefficient scores share the same residual structure. The Gaussian score has the additional common factor \(1/\sigma^2\); for Bernoulli logit and Poisson log-link, the coefficient score is exactly \(X^\mathsf{T}(y-\mu)\). The following statement makes the consequence of a zero score explicit.

Theorem: For any of these three models, at a coefficient vector \(\beta\) with defined fitted means, if the coefficient score is zero, then \(X^\mathsf{T}(y-\mu)=0\). In particular, if the model includes an intercept, the response residuals sum to zero.

Proof. In the Gaussian model the score is \(\sigma^{-2}X^\mathsf{T}(y-\mu)\), and \(\sigma^2>0\), so a zero score implies \(X^\mathsf{T}(y-\mu)=0\). In the Bernoulli logit and Poisson log-link models, the score is already \(X^\mathsf{T}(y-\mu)\), so the same implication holds directly. If the model includes an intercept, one column of \(X\) consists of ones. The component of \(X^\mathsf{T}(y-\mu)\) corresponding to that column is \(\sum_i(y_i-\mu_i)\); because every component is zero, this sum is zero. At a fitted solution, \(\mu_i=\hat\mu_i\), giving the stated fitted-residual checks. \(\square\)

These equations express a covariate-weighted balance: positive and negative residuals must cancel after weighting by each model covariate. They do not require every individual residual to be zero. Nor do they, by themselves, prove that a zero-score point is a maximum or that it is the only solution. The existence and finiteness of solutions are separate questions.

Common Mistake: Checking the Wrong Quantity

A frequent error is to set a score equal to zero using \(y_i-\eta_i\), as if the linear predictor were the fitted response. The score depends on the likelihood through the fitted mean: it uses \(y_i-\eta_i\) only when the particular mean function makes \(\mu_i=\eta_i\), as in the Gaussian identity-link model. For Bernoulli logit, the fitted mean is \(p_i=1/(1+e^{-\eta_i})\); for Poisson log-link, it is \(\mu_i=e^{\eta_i}\). Therefore the correct residuals are \(y_i-p_i\) and \(y_i-e^{\eta_i}\), respectively.

A second related mistake is to check only that the residuals sum to zero. That verifies the intercept equation when an intercept is present, but not the other coefficient equations. Each additional covariate requires its own weighted residual sum to vanish. A reliable check computes the fitted means first, forms the response residuals, and then evaluates every column of \(X^\mathsf{T}(y-\hat\mu)\).

1
Compute the fitted means.
Use the model's mean function, not the linear predictor itself unless the identity link applies.
2
Form response residuals.
For each observation calculate \(y_i-\hat\mu_i\).
3
Check every coefficient.
For each design column \(j\), calculate \(\sum_i x_{ij}(y_i-\hat\mu_i)\); for the Gaussian model, the score includes the factor \(1/\sigma^2\).
Key takeaway: Across Gaussian identity, Bernoulli logit, and Poisson log-link models, the coefficient score is determined by fitted response residuals weighted by the design matrix. A fitted solution must balance those residuals against every included covariate.

Check Your Understanding

Use the likelihood score and fitted mean—not only the form of the linear predictor—to answer these questions.

  1. For a Gaussian identity-link model with common variance \(\sigma^2\), write the score for coefficient \(\beta_j\).
  2. In the Bernoulli logit model, what is the derivative of one observation's log-likelihood with respect to \(\eta_i\)?
  3. For the Poisson log-link model, identify the fitted mean and write the coefficient score vector.
  4. Why does a zero intercept score imply that the residuals sum to zero? What additional checks are needed when there are other covariates?
  5. Explain why \(y_i-\eta_i\) is generally not the correct response residual in either the Bernoulli logit or Poisson log-link model.
Clinical Biostats