Why Use Splines in a Treatment Model?
A continuous covariate in a treatment model need not have a linear association with treatment. For example, treatment probability may change little across the lower range of a laboratory measure, rise sharply around a clinical threshold, and then level off. A model that includes only a linear term imposes a single straight-line relationship on the log odds. If that shape is wrong, the estimated conditional treatment probabilities can be wrong too.
Splines provide a way to represent a smooth, flexible curve without treating every observed value as its own category. In a longitudinal treatment model, a spline can be applied to a continuous variable in the measured pre-treatment history. It changes the functional form for that variable; it does not by itself address whether the history is sufficient for confounding control, whether treatment probabilities are well supported, or whether the treatment model is otherwise appropriate.
Specifying a Spline-Based Treatment Model
Let \(A_{it}\) be the binary treatment for person \(i\) at time \(t\), and let \(H_{it}\) denote the measured history available before that treatment assignment. Suppose \(X_{it}\) is a continuous component of that history. A pooled logistic model can include a spline for \(X_{it}\) alongside other appropriate history terms:
Here \(\alpha_t\) allows a time-specific intercept, \(Z_{it}\) denotes other included history variables, and the spline term specifies the modeled association of \(X_{it}\) with the treatment log odds. The fitted probability is obtained by applying the inverse-logit function to the fitted linear predictor. The spline coefficients generally should be interpreted jointly: a single coefficient usually does not describe the effect of increasing \(X_{it}\) by one unit.
The covariate must be measured before the treatment decision it is used to model. The spline is a functional-form choice, not permission to include future information. Also, a pooled model that uses one set of spline coefficients across times assumes that the modeled curve is shared across those times, apart from the terms explicitly allowed to vary. That assumption should be made deliberately.
Two Useful Spline Bases
A piecewise-linear spline makes the basic construction easy to see. With knots \(\kappa_1,\ldots,\kappa_J\), one representation is \(g(x)=\beta_0+\beta_1x+\sum_{j=1}^J\gamma_j(x-\kappa_j)_+\), where \((u)_+=\max(u,0)\). The fitted curve is linear between knots, and its slope may change at a knot while the curve itself remains continuous.
A commonly used cubic truncated-power basis is \(1,x,x^2,x^3,(x-\kappa_1)_+^3,\ldots,(x-\kappa_J)_+^3\). It allows the cubic polynomial to change after each knot while maintaining continuity of the curve and its first two derivatives. It is one way to construct a cubic regression spline; software may instead use other bases, including B-splines or natural cubic spline bases.
The cubic truncated-power form is useful for understanding the model, but it can be numerically less convenient than locally supported bases such as B-splines. The choice of basis representation does not change the underlying fitted curve when two bases span the same function space and the model includes the corresponding full set of terms.
To verify this, consider the contribution \((x-\kappa)_+^3\) from one knot. For \(x<\kappa\), this term and its first two derivatives are all zero. For \(x>\kappa\), they are \((x-\kappa)^3\), \(3(x-\kappa)^2\), and \(6(x-\kappa)\), respectively. At \(x=\kappa\), the right-hand limits of these three quantities are all zero, matching their values from the left. Adding such terms to a cubic polynomial preserves continuity through the second derivative. Between knots, each positive-part term is either zero or an ordinary cubic polynomial, so the entire function is cubic on that interval. \(\square\)
The treatment probability is not itself a spline: it is the inverse-logit of the spline-based linear predictor. If that predictor is \(g(x)\), then \(p(x)=\exp\{g(x)\}/[1+\exp\{g(x)\}]\), and differentiation gives \(p'(x)=p(x)\{1-p(x)\}g'(x)\). Thus changes in the spline curve alter the probability curve while keeping fitted probabilities between zero and one.
Worked Example: A Piecewise-Linear Treatment Effect
Suppose a fitted model includes the piecewise-linear spline \(\eta(x)=-2+0.3x+0.4(x-2)_+-0.5(x-4)_+\), where \(\eta(x)\) is the treatment log odds. Calculate the fitted probabilities at \(x=1,3,5\), and identify the slope in each interval.
At \(x=1\), both positive-part terms are zero, so \(\eta(1)=-2+0.3=-1.7\). Therefore \(p(1)=1/(1+\exp(1.7))\approx0.1545\).
At \(x=3\), \((3-2)_+=1\) and \((3-4)_+=0\). Thus \(\eta(3)=-2+0.9+0.4=-0.7\), giving \(p(3)=1/(1+\exp(0.7))\approx0.3318\). At \(x=5\), both positive-part terms contribute: \(\eta(5)=-2+1.5+1.2-0.5=0.2\), so \(p(5)=1/(1+\exp(-0.2))\approx0.5498\).
Before the first knot the log-odds slope is \(0.3\). Between 2 and 4 it is \(0.3+0.4=0.7\), and after 4 it is \(0.3+0.4-0.5=0.2\). The fitted log odds remain continuous at both knots, even though their slopes change. These calculations show how a spline can represent a changing association without categorizing \(x\).
Worked Example: Evaluating a Cubic Spline Basis
Consider knots at 1 and 2 and the fitted log-odds curve \(g(x)=-3+0.4x-0.1x^2+0.01x^3-0.02(x-1)_+^3+0.03(x-2)_+^3\). Evaluate the fitted probability at \(x=3\).
The basis values are \(x=3\), \(x^2=9\), \(x^3=27\), \((x-1)_+^3=2^3=8\), and \((x-2)_+^3=1^3=1\). Substitution gives \(g(3)=-3+0.4(3)-0.1(9)+0.01(27)-0.02(8)+0.03(1)\) \(=-3+1.2-0.9+0.27-0.16+0.03=-2.56\).
The treatment probability is \(p(3)=1/(1+\exp(2.56))\approx0.0718\). Every basis value must be calculated at the covariate value of interest; omitting a positive-part term just because it is not part of the original polynomial would give a different, incorrect prediction.
Why a Change of Basis Does Not Change the Model
Different software packages may construct spline terms using different basis functions. When the bases span exactly the same space, the fitted probabilities are unchanged by an invertible re-expression of the columns. This is a useful distinction: a basis is a way to write the model, whereas the function space and constraints determine which curves the model can fit.
For any coefficient vector \(\beta\) in the original model, choose \(\beta^*=C^{-1}\beta\) in the new model. Then \(B^*\beta^*=BC C^{-1}\beta=B\beta\), so the linear predictors match for every observation. Conversely, every \(\beta^*\) corresponds to \(\beta=C\beta^*\). The two models therefore generate exactly the same set of linear predictors. Since the Bernoulli likelihood depends on the observations through those predictors, each possible likelihood value in one parameterization is available in the other. Their maximizing predictors, and hence their inverse-logit fitted probabilities, agree. \(\square\)
Worked Example: A Pooled Model and an Inverse-Probability Weight
Suppose a pooled model uses the cubic predictor \(\eta_{it}=-1+0.2t+0.15x-0.03x^2+0.005x^3+0.04(x-3)_+^3\). For an individual at time \(t=2\) with \(x=4\), calculate the modeled treatment probability. If this individual received treatment, calculate the corresponding unstabilized treatment factor \(1/p\).
The knot term is \((4-3)_+^3=1\). Substituting gives \(\eta_{it}=-1+0.2(2)+0.15(4)-0.03(16)+0.005(64)+0.04(1)\) \(=-1+0.4+0.6-0.48+0.32+0.04=-0.12\).
Thus \(p=\exp(-0.12)/[1+\exp(-0.12)]\approx0.4700\). For the observed treated individual, the inverse-probability treatment factor is \(1/0.4700\approx2.13\). This calculation illustrates how the fitted spline probability enters a weight; it does not establish that the model is correctly specified or that the resulting weight is well behaved.
Choosing Flexibility and Checking the Fit
Spline flexibility is controlled by the basis, number of knots, and knot locations. More knots allow more local changes in shape but require estimating more coefficients. A practical model should use a prespecified or carefully justified level of flexibility rather than selecting a complicated curve solely because it fits observed treatment assignments closely. With limited data in parts of the covariate range, an elaborate curve may be unstable.
Inspect the fitted treatment probabilities against the continuous covariate, preferably while accounting for time and important history variables. Look for implausible bends, abrupt changes not supported by data, and regions where the fitted curve is driven by few observations. Compare the spline specification with a simpler linear specification and, when useful, alternative reasonable knot choices. These checks assess the treatment model’s functional form; they do not prove that all relevant confounders were measured or that the conditional probability model is correct.
Estimated treatment probabilities also enter the inverse-probability weights, so extreme or highly variable weights can signal that some histories receive very small fitted probabilities for the treatment actually observed. This is a reason to investigate the support of the data, model specification, and covariate history—not a reason to choose knots merely to make weights look desirable. Spline flexibility cannot repair a lack of treatment overlap, and fitted values outside the observed covariate range are especially dependent on the chosen basis and extrapolation behavior.
| Approach | What it assumes or permits | Main limitation |
|---|---|---|
| Linear term | A straight-line association on the log-odds scale | Can miss curvature or changes in slope |
| Polynomial terms | A global polynomial curve | Changes in one region can affect the curve elsewhere; high-degree fits may behave erratically |
| Categories of the continuous variable | Separate treatment probabilities across chosen groups | Discards within-group distinctions and depends on cutpoints |
| Spline basis | A flexible curve, with smoothness or continuity determined by its basis | Results depend on flexibility and support; extra terms require data |
Common Mistakes
- Using a post-treatment value. A spline does not make a future or post-assignment covariate appropriate. Include only history available before the treatment being modeled.
- Interpreting one spline coefficient as a constant effect. The effect on log odds varies with \(x\); interpret the combined curve or its predictions.
- Assuming smoothness guarantees correctness. A smooth fitted curve can still omit confounders, use the wrong shape, or be unsupported in parts of the covariate range.
- Choosing knots without considering data support. Flexible local behavior is hard to estimate where few observations occur. Examine the observed range and fitted probabilities.
- Treating a spline basis as categorization. Spline terms use the continuous values and impose a structured curve; they do not estimate an unrelated parameter for every value.
Check Your Understanding
Answer each question, then compare with the short solutions below.
- For \(g(x)=\beta_0+\beta_1x+\gamma(x-3)_+\), what are the slopes below and above the knot, and is the curve continuous at 3?
- Why is a spline coefficient usually not the change in log odds for a one-unit increase in the continuous covariate?
- In a cubic truncated-power spline with knots 1 and 2, what are the two positive-part basis values at \(x=1.5\)?
- Does adding spline terms solve a lack of treatment overlap? Explain.
Solutions. (1) Below 3 the slope is \(\beta_1\); above 3 it is \(\beta_1+\gamma\). At 3 the added term is zero, so the curve is continuous. (2) The log-odds curve combines several basis functions, whose values change with \(x\); the derivative depends on \(x\), rather than being one coefficient. (3) They are \((1.5-1)_+^3=0.5^3=0.125\) and \((1.5-2)_+^3=0\). (4) No. A more flexible model cannot create observed support for treatment decisions absent from the data; it only changes the modeled functional relationship.