Tutorials › Propensity Score Matching and Instrumental Variables › Restricted Cubic Splines in Logistic Score Models

The Balancing Property and Estimation · Tutorial 125 of 699

Restricted Cubic Splines in Logistic Score Models

You will learn how restricted cubic spline terms represent nonlinear covariate effects in logistic propensity models while imposing linear behavior beyond the boundary knots.

Intermediate 11 min read

What You'll Learn

  • Define a restricted cubic spline basis from ordered knots and truncated-cubic functions.
  • Explain how boundary knots constrain spline behavior in the tails.
  • Calculate spline basis values and fitted logistic propensity scores.
  • Choose knot locations while checking data support and sparse tails.
  • Diagnose inadequate functional form without treating treatment prediction as the objective.
  • Compare restricted splines with linear covariate terms and unrestricted cubic splines.

Why Use Restricted Cubic Splines in a Logistic Score Model?

A logistic propensity model can represent a continuous covariate with a straight-line term, but the relationship between that covariate and treatment probability need not be linear on the log-odds scale. A restricted cubic spline adds flexible curvature over the observed range while requiring the fitted relationship to become linear in both tails. This can capture important nonlinear patterns without allowing the curve to keep bending unpredictably beyond the boundary knots.

The spline is a way to specify the covariate's functional form in the logistic model. It does not by itself establish that the model is adequate for causal adjustment. In particular, an apparently good treatment prediction does not guarantee covariate balance or remove confounding by unmeasured variables.

Definition: Let \(X\) be a continuous covariate and let \(t_1<t_2<\cdots<t_K\) be \(K\geq 3\) distinct knots. The first and last knots, \(t_1\) and \(t_K\), are the boundary knots. For a real number \(u\), define the positive-part cube \((u)_+^3=\max(u,0)^3\). A restricted cubic spline basis consists of the linear term \(X\) and \(K-2\) nonlinear terms $$ h_j(X)=\frac{(X-t_j)_+^3-\frac{t_K-t_j}{t_K-t_{K-1}}(X-t_{K-1})_+^3+\frac{t_{K-1}-t_j}{t_K-t_{K-1}}(X-t_K)_+^3}{(t_K-t_1)^2},\qquad j=1,\ldots,K-2. $$ The denominator rescales the cubic combinations so each \(h_j(X)\) has the units of \(X\). This is one standard restricted-spline basis convention; equivalent bases can span the same spline functions.

The logistic propensity model with this basis can be written $$ \operatorname{logit}\{e(X,Z)\}=\log\left\{\frac{e(X,Z)}{1-e(X,Z)}\right\} =\beta_0+\beta_X X+\sum_{j=1}^{K-2}\gamma_jh_j(X)+\boldsymbol{\beta}_Z^\top Z, $$ where \(A\) is the binary treatment indicator, \(Z\) denotes other included covariates, and \(e(X,Z)=P(A=1\mid X,Z)\). The fitted score is $$ \hat e(X,Z)=\frac{\exp\{\hat\eta(X,Z)\}}{1+\exp\{\hat\eta(X,Z)\}}, $$ where \(\hat\eta\) is the fitted linear predictor. The coefficients are estimated by logistic likelihood, as in an ordinary logistic model. The spline changes the columns of the design matrix; it does not change the logistic link or the meaning of the fitted probability.

What the Tail Constraint Does

For \(X\leq t_1\), all positive-part terms in every \(h_j(X)\) are zero. Thus, below the lower boundary knot, the nonlinear basis terms contribute nothing and the predictor varies linearly with \(X\). Above the upper boundary knot, the construction cancels the cubic and quadratic terms, again leaving a linear function of \(X\).

To see the upper-tail constraint, take \(X>t_K\), and write \(a=t_j\), \(b=t_{K-1}\), and \(c=t_K\). The cubic combination in the numerator is $$ (X-a)^3-\frac{c-a}{c-b}(X-b)^3+\frac{b-a}{c-b}(X-c)^3. $$ The coefficient of \(X^3\) is \(1-(c-a)/(c-b)+(b-a)/(c-b)=0\). The coefficient of \(X^2\), divided by \(-3\), is $$ a-\frac{c-a}{c-b}b+\frac{b-a}{c-b}c=0, $$ because \((c-a)b-(b-a)c=a(c-b)\), so the numerator is \(a(c-b)-b(c-a)+c(b-a)=0\). The expression is therefore at most linear in \(X\). The spline permits curvature between knots, but it cannot keep accumulating cubic curvature outside the boundary knots.

Worked Example: Calculating Basis Values at a Covariate Value

Suppose age, measured in years, is represented using four knots \(t_1=40\), \(t_2=55\), \(t_3=65\), and \(t_4=80\). At age \(X=70\), the common denominator is \((80-40)^2=1600\). There are \(K-2=2\) nonlinear terms.

For \(j=1\), \(t_j=40\), and the two multipliers in the formula are \((80-40)/(80-65)=40/15\) and \((65-40)/(80-65)=25/15\). Since \(70-80<0\), the last positive-part term is zero: $$ h_1(70)=\frac{27000-(40/15)(125)+(25/15)(0)}{1600} =\frac{26666.6667}{1600} \approx 16.6667. $$

For \(j=2\), \(t_j=55\), so the multipliers are \(25/15\) and \(10/15\): $$ h_2(70)=\frac{3375-(25/15)(125)+(10/15)(0)}{1600} =\frac{3166.6667}{1600} \approx 1.9792. $$ The basis at age 70 is therefore the original linear term \(70\), together with \(h_1(70)\approx16.6667\) and \(h_2(70)\approx1.9792\). The nonlinear terms are calculated from the knots and the covariate value; they are not extra observed covariates.

Choosing Knots and Fitting Scores

Knot placement determines where the spline can change curvature. A common practical choice places interior knots at selected sample quantiles of the continuous covariate, with boundary knots at the extremes of the supported range. A small number of knots, often three to five, is a reasonable starting point in many applications, but there is no universally correct number. More knots add flexibility and parameters, and can make estimates unstable when observations are sparse in parts of the covariate range.

Knot choices should be based on the covariate distribution and the modeling purpose, not on a search for the specification that best predicts treatment assignment. If boundary knots are set at observed extremes, the spline is linear beyond those values; this does not mean predictions far outside the observed range are trustworthy. The model has little or no empirical support there. If tied values or a narrow range leave too few distinct knot locations, a spline with that many knots cannot be constructed as specified.

Worked Example: Choosing Knots From a Hypothetical Covariate Sample

Consider a hypothetical sample of 20 patients with ages, in years, already sorted as follows: 22, 25, 29, 31, 34, 36, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 72, 75, and 78. For illustration, choose four knots at order-statistic ranks 1, 7, 14, and 20. This explicit rank rule gives knots \(22,38,59,78\); it is an illustrative choice, not a universal quantile rule.

The denominator for this basis is \((78-22)^2=3136\), and \(t_{K-1}=59\). At age 50, both positive-part terms involving 59 and 78 are zero. Thus $$ h_1(50)=\frac{(50-22)^3}{3136}=\frac{21952}{3136}=7, \qquad h_2(50)=\frac{(50-38)^3}{3136}=\frac{1728}{3136}\approx0.5510. $$ These values show how the selected knots determine the basis columns. Before fitting, check that the locations are distinct, lie in the intended covariate range, and do not leave very sparse regions where the curvature would be driven by few observations.

Worked Example: Turning a Nonlinear Predictor Into a Fitted Score

Return to the four knots \(40,55,65,80\) and suppose a hypothetical fitted logistic model for age alone is $$ \hat\eta(X)=-2+0.015X+0.040h_1(X)-0.050h_2(X). $$ The coefficients are illustrative fitted values, not estimates from a real study. At age 70, use the basis values already calculated: $$ \hat\eta(70)=-2+0.015(70)+0.040(16.6667)-0.050(1.9792) \approx -0.3823. $$ Therefore $$ \hat e(70)=\frac{\exp(-0.3823)}{1+\exp(-0.3823)} \approx\frac{0.6823}{1+0.6823} \approx0.4056. $$ The model assigns a treatment probability of about 0.406 to a person with age 70 years, under this hypothetical model.

For a second calculation, evaluate the basis at age 85, beyond the upper boundary knot. For \(h_1\), the positive-part cubes are \(45^3\), \(20^3\), and \(5^3\); for \(h_2\), they are \(30^3\), \(20^3\), and \(5^3\). Hence $$ h_1(85)=\frac{91125-(40/15)(8000)+(25/15)(125)}{1600} =\frac{70000}{1600}=43.75, $$ $$ h_2(85)=\frac{27000-(25/15)(8000)+(10/15)(125)}{1600} =\frac{13750}{1600}=8.59375. $$ Then \(\hat\eta(85)=-2+0.015(85)+0.040(43.75)-0.050(8.59375)=0.5953\), giving $$ \hat e(85)=\frac{\exp(0.5953)}{1+\exp(0.5953)}\approx0.6445. $$ This is the model's extrapolated score at age 85, not evidence that its estimate is reliable there. The tail is constrained to be linear on the log-odds scale, but the data may provide little support beyond age 80.

Diagnostics, Comparisons, and Limitations

After fitting, examine whether the estimated functional form is plausible and whether its use supports the intended adjustment. Plot fitted treatment probabilities against the continuous covariate, marking the knot locations and noting the density of observations. Look for abrupt changes, extreme fitted probabilities in sparse regions, or tail behavior that is being determined by very few observations. Compare the covariate distributions across treatment groups, and assess balance in the original continuous covariate; a flexible model is not a substitute for checking balance after the planned adjustment procedure.

SpecificationWhat it allowsMain consideration
One linear covariate termA straight-line relationship between the covariate and log odds of treatmentSimple, but can be inadequate if the relationship is curved
Restricted cubic splineFlexible curvature between knots and linear behavior beyond the boundary knotsRequires choices about knot number and placement; sparse regions can destabilize the fitted curve
Unrestricted cubic splineCubic behavior without the same linear-tail constraintCan bend more in the tails, where data are often limited

A restricted spline is not guaranteed to improve a propensity model simply because it has more flexibility. Too many knots can create noisy estimates, while too few can leave important curvature unrepresented. A poor choice of boundary knots can also make the linear-tail restriction unrealistic over a meaningful portion of the data. The basis's coefficients are not usually interpreted one at a time as simple changes in odds; fitted probabilities or contrasts in the model's predicted odds across relevant covariate values are more informative.

A frequent mistake is to conclude that a restricted cubic spline is “linear” because its tails are linear, and therefore it adds nothing beyond a linear term. That is incorrect: the restriction applies outside the boundary knots, whereas the terms \(h_j(X)\) allow the fitted log odds to curve over the interior range. The opposite mistake is to assume that flexible curvature guarantees adequate confounding control. The basis only represents the measured covariate's form in the treatment model; it cannot correct omitted confounders or poor overlap. The earlier material on choosing covariates for a propensity model addresses the separate question of which covariates to include.

Key takeaway: A restricted cubic spline adds \(K-2\) nonlinear basis terms to a linear covariate term using \(K\) ordered knots. It allows curvature within the boundary knots and enforces linear tails, but the fitted propensity model still requires careful diagnostics and substantive judgment.

Check Your Understanding

Answer each question, then compare with the worked solutions below.

  1. With \(K=5\) distinct knots, how many nonlinear basis terms are used, and what are the boundary knots?
  2. For the knots \(40,55,65,80\), why is the final positive-part term in \(h_1(70)\) zero? What is its multiplier?
  3. Using the fitted model in the score example, calculate the linear predictor and score at age 55, where \(h_1(55)=3375/1600\) and \(h_2(55)=0\).
  4. What does the linear-tail constraint imply beyond the upper boundary knot, and what does it not imply about the reliability of predictions there?
  5. A spline model produces attractive treatment predictions but leaves the original continuous covariate imbalanced after adjustment. Is the spline necessarily adequate for the intended use? Explain.

Solutions. (1) There are \(K-2=3\) nonlinear terms. The boundary knots are the first and fifth knots, \(t_1\) and \(t_5\). (2) Since \(70-80=-10<0\), \((70-80)_+^3=0\). The multiplier is \((t_{K-1}-t_1)/(t_K-t_{K-1})=(65-40)/(80-65)=25/15\). (3) At age 55, \(h_1=3375/1600=2.109375\) and \(h_2=0\). Thus \(\hat\eta(55)=-2+0.015(55)+0.040(2.109375)=-1.090625\), so \(\hat e(55)=\exp(-1.090625)/[1+\exp(-1.090625)]\approx0.2515\). (4) Beyond the upper knot, the spline contribution to the log odds is linear in the covariate. This mathematical constraint does not establish that the data support accurate extrapolation there. (5) No. Treatment prediction alone does not establish adequate adjustment; residual covariate imbalance is a warning that the intended procedure may not be achieving the required balance.

Clinical Biostats