Tutorials › Exam PA - Predictive Analytics › Deriving Weighted GLM Score Equations

Exam PA · Model Comparison, Offsets, and Weights · Tutorial 389 of 966

Deriving Weighted GLM Score Equations

Learn to derive and solve weighted GLM score equations, then interpret what observation weights change—and what they do not.

Advanced 14 min read

What You'll Learn

  • Derive the weighted score vector from a weighted log-likelihood.
  • Write the score equation for canonical and noncanonical links.
  • Relate the score to the working weights used in iteratively reweighted least squares.
  • Solve weighted Poisson, Gaussian, and grouped-binomial examples.
  • Distinguish case weights from the response model’s link function.
  • Identify common errors involving weight placement and binomial trial counts.

Why Derive a Weighted Score Equation?

A generalized linear model (GLM) uses a specified response distribution, a linear predictor, and a link function to relate the mean response to predictors. When observations have different weights, the fitted coefficients are determined by a weighted objective: a case with a larger weight contributes more to the estimation equations. Deriving those equations makes the effect precise and helps distinguish weighting from changing the model itself. The material is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

This tutorial treats weights as fixed, nonnegative multipliers on observation-level log-likelihood contributions. A weight of zero removes that case from the objective; a larger positive weight gives its contribution more influence. The equations below do not, by themselves, decide why a particular weighting scheme is appropriate. That interpretation depends on the data and the modeling purpose.

Definition: For independent responses \(Y_i\), a weighted log-likelihood is \(\ell_w(\beta)=\sum_{i=1}^n w_i\ell_i(\beta)\), where \(\ell_i(\beta)\) is the log-likelihood contribution from observation \(i\), and \(w_i\) is its fixed, nonnegative weight. The weighted score is the derivative of this weighted log-likelihood with respect to the coefficient vector \(\beta\). A maximum-likelihood estimate in the interior of the parameter space satisfies a zero weighted score.

Deriving the General Weighted Score

Suppose each response follows an exponential-family model with log-likelihood contribution, apart from terms not involving the model parameters, \(\ell_i=(y_i\theta_i-b(\theta_i))/\phi\). Here \(\theta_i\) is the natural parameter, \(\phi\) is a common dispersion parameter, and the mean is \(\mu_i=b'(\theta_i)\). The variance has the form \(\operatorname{Var}(Y_i)=\phi V(\mu_i)\). The GLM specifies \(\eta_i=x_i^\mathsf{T}\beta\) and \(g(\mu_i)=\eta_i\), where \(x_i\) is the predictor vector and \(g\) is the link.

Assume the responses are conditionally independent, the family and link are differentiable, and the means lie in the interior of the allowed parameter range. These conditions allow differentiation of the likelihood. The dispersion is treated as fixed for this coefficient-score derivation.

1
Differentiate the weighted objective.
Because the weights are fixed, differentiating \(\ell_w=\sum_iw_i\ell_i\) multiplies each observation’s ordinary score by \(w_i\).
2
Differentiate through the mean and link.
Since \(d\ell_i/d\theta_i=(y_i-\mu_i)/\phi\), the chain rule gives \(d\ell_i/d\beta=(y_i-\mu_i)(d\theta_i/d\mu_i)(d\mu_i/d\eta_i)x_i/\phi\).
3
Use the variance function.
The exponential-family variance relationship gives \(d\mu_i/d\theta_i=V(\mu_i)\), hence \(d\theta_i/d\mu_i=1/V(\mu_i)\).

Combining the steps gives the general weighted score vector. The estimate is found by setting this vector equal to zero and solving for \(\beta\).

$$ U_w(\beta)= \sum_{i=1}^n w_i x_i \frac{(y_i-\mu_i)(d\mu_i/d\eta_i)} {\phi V(\mu_i)} =\mathbf{0}. $$

This formula also shows why a weight changes a case’s contribution to estimation: it multiplies that case’s score. It does not appear inside \(g\), nor does it change the relationship \(g(\mu_i)=\eta_i\). A noncanonical link generally leaves the factor \((d\mu_i/d\eta_i)/V(\mu_i)\) in the score. It is not generally correct to use the simpler canonical-link equation for every GLM.

Canonical-link result: If the link is canonical, then \(\eta_i=\theta_i\). In that case \(d\mu_i/d\eta_i=V(\mu_i)\), so the score simplifies to \(U_w(\beta)=\sum_i w_i x_i(y_i-\mu_i)/\phi=\mathbf{0}\). This simplification does not apply automatically to a noncanonical link.

Connection to Working Weights

The score can be written in the form used by iteratively reweighted least squares (IRLS). Define the working response \(z_i=\eta_i+(y_i-\mu_i)/(d\mu_i/d\eta_i)\), and define the working weight \(W_i=w_i(d\mu_i/d\eta_i)^2/(\phi V(\mu_i))\). Then \(W_i(z_i-\eta_i)\) equals the \(i\)th scalar residual contribution to the score before multiplication by \(x_i\). Thus the score equation is \(X^\mathsf{T}W(z-\eta)=\mathbf{0}\), where \(W\) is the diagonal matrix of working weights.

The working weights vary with the current fitted means for a general GLM. They combine the observation weight with the model’s variance and link behavior. They are not a replacement link function: the model still uses the stated \(g\). IRLS repeatedly updates the working response and working weights to find a solution to the original score equations.

Worked Example: Weighted Poisson Regression with a Binary Predictor

A hypothetical portfolio has two risk groups, \(x=0\) and \(x=1\). Under a Poisson log-link model, observations in group 0 are \((y,w)=(1,1)\) and \((3,5)\); observations in group 1 are \((2,1)\) and \((4,1)\). Fit the weighted score equations for \(\eta_i=\beta_0+\beta_1x_i\). Use the Poisson model’s canonical log link.

Method. For Poisson responses, \(\phi=1\), \(V(\mu)=\mu\), and the log link is canonical. The score equations are \(\sum_i w_ix_i(y_i-\mu_i)=0\) and \(\sum_iw_i(y_i-\mu_i)=0\). With a binary predictor, the first equation sets the weighted residual sum in group 1 to zero; subtracting it from the intercept equation sets the group 0 residual sum to zero as well.

For group 0, the weighted response total is \(1(1)+5(3)=16\), and the total weight is \(1+5=6\). Therefore \(\hat\mu_0=16/6=8/3\). For group 1, the corresponding total is \(1(2)+1(4)=6\), with total weight \(2\), so \(\hat\mu_1=6/2=3\).

The fitted means satisfy \(\hat\mu_0=e^{\hat\beta_0}\) and \(\hat\mu_1=e^{\hat\beta_0+\hat\beta_1}\). Hence \(\hat\beta_0=\log(8/3)\approx0.9808\), and \(\hat\beta_1=\log(3)-\log(8/3)=\log(9/8)\approx0.1178\), rounded to four decimal places.

Check. In group 0, the weighted residual sum is \(1(1-8/3)+5(3-8/3)=-5/3+5/3=0\). In group 1, it is \(1(2-3)+1(4-3)=-1+1=0\). Both group sums are zero, so the intercept score and the \(x\)-coefficient score are zero. The common mistake is to report \(\log(3)-\log(8/3)\) with an inaccurate decimal; the difference is \(\log(9/8)\approx0.1178\), not \(0.1173\).

Weighted Gaussian Regression

For a normal response with \(\mu_i=x_i^\mathsf{T}\beta\), identity link, and common variance \(\sigma^2\), the score is \(\sum_i w_ix_i(y_i-\mu_i)/\sigma^2=\mathbf{0}\). Since the nonzero common factor \(1/\sigma^2\) cancels, the coefficient estimate solves the weighted least-squares normal equations \(X^\mathsf{T}WX\beta=X^\mathsf{T}Wy\). This result relies on the identity link and the stated Gaussian variance structure.

Worked Example: Solving a Weighted Gaussian Score

A hypothetical pricing study records \((x,y,w)=(0,1,1),(1,2,2),(2,4,1)\). Assume independent normal responses with mean \(\beta_0+\beta_1x\), identity link, and common fixed variance \(\sigma^2\). Find the weighted score estimate.

The weighted totals are \(\sum w_i=4\), \(\sum w_ix_i=4\), and \(\sum w_iy_i=9\). Therefore \(\bar{x}_w=4/4=1\) and \(\bar{y}_w=9/4=2.25\). The weighted sum of squared centered predictors is \(1(0-1)^2+2(1-1)^2+1(2-1)^2=2\). The weighted centered cross-product is \(1(0-1)(1-2.25)+2(1-1)(2-2.25)+1(2-1)(4-2.25)=1.25+0+1.75=3\).

Thus \(\hat\beta_1=3/2=1.5\) and \(\hat\beta_0=\bar{y}_w-\hat\beta_1\bar{x}_w=2.25-1.5=0.75\). The fitted values at \(x=0,1,2\) are \(0.75,2.25,3.75\), giving residuals \(0.25,-0.25,0.25\).

Check. The weighted residual sum is \(1(0.25)+2(-0.25)+1(0.25)=0\), and the weighted predictor-residual sum is \(1(0)(0.25)+2(1)(-0.25)+1(2)(0.25)=0\). Both Gaussian score equations are satisfied. The unweighted fit would solve different equations; using it would ignore the specified influence of the weight 2 at \(x=1\).

Grouped Binomial Responses and Weights

For grouped binomial data, let \(r_i\) be the number of successes out of \(m_i\) trials, and let \(p_i\) be the success probability. Under a logit link, the canonical score for additional case weights \(w_i\) is \(\sum_iw_ix_i(r_i-m_ip_i)=\mathbf{0}\). The number of trials \(m_i\) is part of the binomial response likelihood; an additional case weight \(w_i\) multiplies that entire grouped likelihood contribution.

Worked Example: Weighted Intercept-Only Binomial Model

A hypothetical service team records 1 success in 2 trials for one segment, with case weight 1, and 4 successes in 5 trials for another segment, with case weight 3. Fit an intercept-only binomial model with logit link. Let \(p\) denote its common success probability.

The weighted canonical score is \(\sum_iw_i(r_i-m_ip)=0\). Substituting the two records gives \(1(1-2p)+3(4-5p)=0\), or \(1-2p+12-15p=0\). Therefore \(13-17p=0\), so \(\hat p=13/17\).

The intercept estimate is \(\hat\beta_0=\log(\hat p/(1-\hat p))=\log((13/17)/(4/17))=\log(13/4)\approx1.1787\), rounded to four decimal places. To check the score, the first record contributes \(1(1-26/17)=-9/17\); the second contributes \(3(4-65/17)=9/17\). Their sum is zero.

Common mistake avoided. Omitting the case weight of 3 gives the unweighted proportion \((1+4)/(2+5)=5/7\), which is not the requested estimate. Conversely, treating the weight 3 as if it replaced the second record’s 5 trials also gives the wrong equation. The correct contribution uses both: \(w_i(r_i-m_ip_i)\).

What the Weights Change—and What They Do Not

The weighted score makes the distinction direct. The link determines how a linear predictor maps to the mean; for example, a log link requires \(\mu_i=e^{\eta_i}\), while a logit link requires \(p_i=e^{\eta_i}/(1+e^{\eta_i})\). Multiplying a likelihood contribution by \(w_i\) does not change either mapping. It changes how strongly that observation’s residual pattern affects the coefficient estimate.

Weights also do not guarantee that an estimate is a solution in closed form. The Poisson binary-predictor example and the intercept-only binomial example admitted simple weighted means because their predictors allowed direct group or intercept solutions. More general GLMs usually require numerical optimization or IRLS. If weights are fractional or are not literal replication counts, a weighted likelihood can be a useful estimation objective, but it should not automatically be interpreted as an ordinary likelihood for an expanded sample.

A frequent exam trap is to conflate the weight with a predictor effect. A weight does not add a term to \(\eta_i\); it multiplies the observation’s contribution to the score. Another trap is to use the canonical simplification under a noncanonical link. In that case, return to the general score and retain the derivative and variance-function factors.

Key takeaway: Begin with the weighted log-likelihood, differentiate by the chain rule, and only then simplify for the chosen family and link. Each case’s score is multiplied by its weight; the link function and its mean-predictor relationship remain as specified.

Check Your Understanding

For each problem, write the relevant weighted score before calculating. Answers are included at the end of each question.

  1. A Poisson intercept-only log-link model has counts \(1,2,6\) with weights \(1,2,1\). Find the fitted mean and intercept. (Answer: \(\hat\mu=11/4=2.75,\ \hat\beta_0=\log(2.75)\approx1.0116\).)
  2. For a Gaussian identity-link model, the observations \((x,y,w)\) are \((0,2,1),(1,3,2),(3,7,1)\). Find the weighted least-squares slope and intercept. (Answer: \(\hat\beta_1=33/19\approx1.7368,\ \hat\beta_0=30/19\approx1.5789\).)
  3. An intercept-only logit model has grouped records \((r,m,w)=(3,4,2)\) and \((2,6,1)\). Find the fitted probability and intercept. (Answer: \(\hat p=4/7,\ \hat\beta_0=\log(4/3)\approx0.2877\).)
  4. A Poisson log-link model has a binary predictor. At \(x=0\), the rows are \((y,w)=(1,1),(3,2)\); at \(x=1\), they are \((2,1),(5,1)\). Find the two fitted group means and both coefficients. (Answer: \(\hat\mu_0=7/3,\ \hat\mu_1=7/2,\ \hat\beta_0=\log(7/3)\approx0.8473,\ \hat\beta_1=\log(3/2)\approx0.4055\).)
  5. In a logistic model with binary predictor \(x\), at \(x=0\) there is one outcome 0 with weight 1 and one outcome 1 with weight 3; at \(x=1\), there is one outcome 1 with weight 2 and one outcome 0 with weight 1. Find each fitted group probability and the coefficients. (Answer: \(\hat p_0=3/4,\ \hat p_1=2/3,\ \hat\beta_0=\log 3,\ \hat\beta_1=\log(2/3)\approx-0.4055\).)
Clinical Biostats