Tutorials › Marginal Structural Models › Score Equations for Logistic Treatment Models

Inverse Probability of Treatment Weights · Tutorial 116 of 501

Score Equations for Logistic Treatment Models

Learn how logistic score equations determine fitted treatment probabilities and, in turn, the inverse weights used for a single treatment decision.

Advanced 11 min read

What You'll Learn

  • Derive the logistic treatment-model score from the Bernoulli likelihood.
  • Interpret the score equations as fitted residual sums equaling zero.
  • State conditions for a unique finite maximum-likelihood estimate and identify separation.
  • Compute fitted probabilities and inverse weights in simple examples.
  • Distinguish likelihood score balance from exact balance under inverse weighting.
  • Use score residuals and fitted probabilities to diagnose estimation problems.

From a Treatment Model to Fitted Weights

For a binary treatment \(A\), an inverse probability weight uses the probability of the treatment actually received, conditional on measured covariates. In practice, that probability is often estimated with logistic regression. The model’s score equations explain what the fitted probabilities satisfy in the observed sample—and, just as importantly, what they do not guarantee about the resulting weights.

Consider one treatment decision observed for \(n\) independent individuals. Let \(A_i\in\{0,1\}\) be individual \(i\)'s treatment and let \(\mathbf z_i\) be a vector of specified covariate functions, usually including an intercept. The logistic model is \(P(A_i=1\mid \mathbf z_i)=p_i(\boldsymbol\beta)=\operatorname{expit}(\mathbf z_i^\mathsf{T}\boldsymbol\beta)\), where \(\operatorname{expit}(u)=1/(1+\exp(-u))\). The model is conditional on the chosen covariates and functional form; fitting it does not by itself establish that these are adequate for causal weighting.

Definition: For independent binary treatment observations and a logistic treatment model, the maximum-likelihood score is the vector of derivatives of the log-likelihood with respect to \(\boldsymbol\beta\). A finite maximum-likelihood estimate \(\hat{\boldsymbol\beta}\) solves \(\sum_{i=1}^n \mathbf z_i\{A_i-p_i(\hat{\boldsymbol\beta})\}=\mathbf 0\). The fitted treatment probability is \(\hat p_i=p_i(\hat{\boldsymbol\beta})\).

The corresponding unstabilized inverse probability of treatment weight for this single decision is \(\hat W_i=A_i/\hat p_i+(1-A_i)/(1-\hat p_i)\). Thus a treated individual receives \(1/\hat p_i\), while an untreated individual receives \(1/(1-\hat p_i)\). The score equations determine the fitted probabilities through the likelihood; the weights are then calculated from those probabilities.

Deriving the Score Equations

Conditional on the observed covariates, the Bernoulli likelihood and log-likelihood are

$$ L(\boldsymbol\beta)=\prod_{i=1}^n p_i(\boldsymbol\beta)^{A_i} \{1-p_i(\boldsymbol\beta)\}^{1-A_i}, \qquad \ell(\boldsymbol\beta)=\sum_{i=1}^n \left[A_i\log p_i+(1-A_i)\log(1-p_i)\right]. $$

Since \(\partial p_i/\partial\boldsymbol\beta=p_i(1-p_i)\mathbf z_i\), differentiating an individual log-likelihood contribution gives

$$ \begin{aligned} \frac{\partial}{\partial\boldsymbol\beta} \left[A_i\log p_i+(1-A_i)\log(1-p_i)\right] &=A_i(1-p_i)\mathbf z_i-(1-A_i)p_i\mathbf z_i\\ &=\mathbf z_i(A_i-p_i). \end{aligned} $$

Summing these contributions yields the score \(U(\boldsymbol\beta)=\sum_i\mathbf z_i(A_i-p_i)\). The maximum-likelihood score equations set each component to zero. With an intercept, one equation is \(\sum_i(A_i-p_i)=0\); for each other model column \(z_{ij}\), the equation is \(\sum_i z_{ij}(A_i-p_i)=0\).

Result: In an unpenalized logistic model containing an intercept, any finite maximum-likelihood estimate satisfies \(\sum_i\hat p_i=\sum_i A_i\). More generally, it satisfies \(\sum_i\mathbf z_i\hat p_i=\sum_i\mathbf z_i A_i\). These are fitted-residual equations, not general equations stating that inverse-weighted covariate means are equal across treatment groups.

To verify the result, take the intercept component of the score equation. Its covariate value is \(1\) for every individual, so that component is \(\sum_i(A_i-\hat p_i)=0\), which rearranges to the stated equality. The other components follow by applying the same equation to their corresponding columns of \(\mathbf z_i\).

Existence, Concavity, and Uniqueness

The score equations describe a finite estimate only when a finite solution exists. The Hessian, the matrix of second derivatives of the log-likelihood, is

$$ H(\boldsymbol\beta) =\frac{\partial U(\boldsymbol\beta)}{\partial\boldsymbol\beta^\mathsf{T}} =-\sum_{i=1}^n p_i(1-p_i)\mathbf z_i\mathbf z_i^\mathsf{T}. $$

For any vector \(\mathbf v\), \(\mathbf v^\mathsf{T}H(\boldsymbol\beta)\mathbf v =-\sum_i p_i(1-p_i)(\mathbf z_i^\mathsf{T}\mathbf v)^2\leq 0\). Thus the log-likelihood is concave. If the design matrix with rows \(\mathbf z_i^\mathsf{T}\) has full column rank, then for any nonzero \(\mathbf v\) at least one \(\mathbf z_i^\mathsf{T}\mathbf v\ne0\). At finite \(\boldsymbol\beta\), every \(p_i(1-p_i)>0\), so the quadratic form is strictly negative. The log-likelihood is then strictly concave, and there can be at most one finite maximizer.

This proves uniqueness if a finite maximizer exists; it does not prove existence. For example, complete separation can make the likelihood approach its supremum as a coefficient diverges, without attaining that supremum at any finite coefficient. When a finite maximizer exists, concavity makes a score root a global maximum; with full column rank, it is the unique finite maximum. \(\square\)

Worked Example: Intercept-Only Treatment Model

Suppose five independent individuals have treatments \(A=(1,0,1,0,0)\), and fit a logistic model with an intercept only. Write the intercept as \(\beta_0\), so every individual has fitted probability \(p=\operatorname{expit}(\beta_0)\).

The intercept score equation is \(\sum_i(A_i-p)=0\). There are two treated individuals, so \(2-5p=0\), giving \(\hat p=2/5=0.4\). The fitted intercept is \(\hat\beta_0=\log\{0.4/0.6\}=\log(2/3)\).

Each treated individual's weight is \(1/0.4=2.5\), and each untreated individual's weight is \(1/0.6=5/3\). The total treated weight is \(2(2.5)=5\); the total untreated weight is \(3(5/3)=5\). Here both totals equal the sample size because the fitted probability is the observed treatment proportion in this intercept-only model.

That equality of arm-specific total weights is not a general consequence of fitting logistic regression with covariates. The general intercept score instead says that the sum of fitted probabilities equals the number treated.

Worked Example: A Logistic Model With a Binary Covariate

Suppose a binary covariate \(L\) defines two groups of four individuals each. In the \(L=0\) group, one individual is treated; in the \(L=1\) group, three are treated. Fit a logistic model with an intercept and \(L\): \(\operatorname{logit}(p_i)=\beta_0+\beta_1L_i\).

The score equation for the intercept says the total fitted treatment count is \(1+3=4\). The score equation for \(L\) says the fitted treatment count in the \(L=1\) group is \(3\). Since all four individuals in that group share a fitted probability, \(\hat p_1=3/4\). The intercept equation then requires the fitted count in the \(L=0\) group to be \(4-3=1\), so \(\hat p_0=1/4\).

These probabilities correspond to \(\hat\beta_0=\operatorname{logit}(1/4)=-\log 3\) and \(\hat\beta_1=\operatorname{logit}(3/4)-\operatorname{logit}(1/4)=2\log 3\). The fitted probabilities reproduce the observed treatment proportions in both groups because this model has a separate fitted probability for each value of \(L\).

For \(L=0\), the treated individual has weight \(1/(1/4)=4\), and each of the three untreated individuals has weight \(1/(3/4)=4/3\). For \(L=1\), each of the three treated individuals has weight \(1/(3/4)=4/3\), and the untreated individual has weight \(1/(1/4)=4\). In each group the treated weight total and untreated weight total are both \(4\). This exact within-group equality follows from the saturated group-specific fit; it should not be assumed for a general logistic model.

Worked Example: Complete Separation and No Finite Score Root

Suppose three individuals have \(L=0\) and are all untreated, while three have \(L=1\) and are all treated. Fit the intercept-and-\(L\) logistic model. The observed treatment outcomes are perfectly separated by \(L\).

In the \(L=0\) group, the likelihood is maximized by taking its fitted probability toward \(0\); in the \(L=1\) group, it is maximized by taking its fitted probability toward \(1\). The group-specific probabilities can be written as \(p_0=\operatorname{expit}(\beta_0)\) and \(p_1=\operatorname{expit}(\beta_0+\beta_1)\). Sending \(\beta_0\) toward \(-\infty\) and \(\beta_0+\beta_1\) toward \(+\infty\) makes both group contributions approach their largest possible value, while requiring diverging coefficients.

At any finite coefficients, \(0<p_0,p_1<1\), so the \(L=0\) score component for its group is \(-3p_0<0\), and the \(L=1\) group score contribution is \(3(1-p_1)>0\). Both cannot be zero at finite probabilities. Thus there is no finite score root or finite maximum-likelihood estimate. Numerical software may report very large coefficients or fail to converge; probabilities near zero or one would also produce very large inverse weights for observations receiving the treatment modeled as rare.

What the Score Does—and Does Not—Balance

The score equation \(\sum_i\mathbf z_i(A_i-\hat p_i)=0\) is often described as a balance property. Precisely, the observed treatment indicators and fitted probabilities have matching totals when multiplied by each included design column. It does not generally say that the inverse-weighted covariate totals for treated and untreated individuals match.

The distinction is visible in the weight formula: treated records contribute \(\mathbf z_i/\hat p_i\) to a treated weighted sum, while the score involves \(\mathbf z_i(A_i-\hat p_i)\). These are different expressions. Exact balance can occur in special designs, as in the group-saturated example, but it does not follow from the logistic score equations alone. Nor does solving the score establish that the treatment model is correctly specified, that all confounders are measured, or that positivity holds.

Useful diagnostics include checking whether the fitting algorithm converged to a finite solution, inspecting the magnitude of coefficients and standard errors, and examining fitted probabilities for values close to zero or one. A small score norm, \(\lVert U(\hat{\boldsymbol\beta})\rVert\), indicates numerical satisfaction of the estimating equations; it is not evidence that the model is causally adequate. Separation, sparse covariate patterns, an ill-conditioned design matrix, or extreme fitted probabilities can undermine the practical use of the resulting weights.

Compared with an intercept-only model, a covariate-adjusted logistic model allows treatment probabilities to vary with measured covariates. A saturated model for discrete covariate patterns estimates a separate treatment proportion in each pattern, when data support it. Other treatment-probability estimators, including random forests and ensemble methods, use different fitting procedures and need not obey these logistic score equations. Whatever the fitting approach, the estimated probabilities must be assessed for their suitability as denominators; a converged logistic fit does not remove the need to consider overlap and model specification.

Common pitfall: “The logistic score equations are zero, so the inverse-weighted groups must be exactly covariate-balanced.” This conclusion does not follow. The score matches sums of \(\mathbf z_i A_i\) and \(\mathbf z_i\hat p_i\); inverse weighting instead uses terms such as \(\mathbf z_i A_i/\hat p_i\). Check the actual weighted quantities rather than treating these distinct equations as interchangeable.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. In a logistic treatment model, what is the score vector, and what does its intercept equation imply when the model includes an intercept?
  2. There are eight individuals in an intercept-only model, with three treated. What is the fitted treatment probability and the weight for an untreated individual?
  3. Why does a full-column-rank design imply at most one finite logistic maximum, but not guarantee that one exists?
  4. Does the logistic score equation guarantee exact inverse-weighted covariate balance? Explain the distinction.
  5. Name one warning sign of separation and explain its relevance to fitted inverse weights.

Solutions. (1) The score is \(\sum_i\mathbf z_i(A_i-p_i)\). Its intercept component gives \(\sum_i\hat p_i=\sum_iA_i\). (2) The score gives \(\hat p=3/8\); an untreated individual's weight is \(1/(1-3/8)=8/5\). (3) Full column rank makes the Hessian negative definite at finite coefficients, so the log-likelihood is strictly concave and has at most one finite maximizer. It may still approach its supremum only as coefficients diverge, as under separation. (4) No. The score matches design-column sums of observed treatment and fitted probabilities; inverse-weighted sums use treatment indicators divided by fitted probabilities. These are not generally equal. (5) Very large coefficients, enormous standard errors, or nonconvergence can indicate separation. Fitted probabilities near zero or one can create very large inverse weights for some observations.

Clinical Biostats