Why the Functional Form Matters
A weighted Cox marginal structural model can represent the effect of treatment history through cumulative duration. But “include cumulative duration” does not determine a model: a linear term, duration categories, and a spline impose different relationships between exposure and the log hazard. Those restrictions affect both fitted values and the hazard contrasts reported for treatment regimes. The choice is therefore substantive, not merely a matter of presentation.
Let \(A_i(s)\) indicate whether person \(i\) is treated at time \(s\), with values 0 or 1. Define cumulative treatment duration by time \(t\) as \(D_i(t)=\int_0^t A_i(s)\,ds\). In discrete person-period data, this is the sum of treated interval lengths through \(t\). It measures total time treated, including separated periods of treatment; it is not necessarily time since the first treatment initiation. In a hazard model, use the duration accumulated just before the interval’s event risk, denoted \(D_i(t-)\), so the covariate does not use treatment information from after that point.
This model states a structural hazard relationship in the weighted pseudo-population; it is not an ordinary regression adjustment for measured confounders. Its causal interpretation requires consistency, sequential exchangeability given measured treatment and censoring histories, and positivity for the treatment histories being contrasted. The weights must correctly address the relevant treatment and censoring processes. The duration summary and the chosen function \(f\) must also be adequate for the target relationship. For estimation, the duration covariate must be correctly aligned with event intervals, and weighted Cox risk sets must represent the intended target population. These conditions do not make a restrictive functional form correct automatically.
Three Representations of Duration
A linear specification uses \(f(d)=\beta d\). It assumes a constant change in log hazard per unit of cumulative duration. A categorical specification assigns a separate log-hazard contribution to each duration band, allowing a stepwise relationship but treating durations within a band as equivalent. A spline represents \(f\) with a sum of smooth basis functions. It can allow the slope to change over duration without requiring abrupt jumps at category boundaries.
A simple spline is a piecewise-linear spline, built from hinge functions \((d-\kappa)_+=\max(d-\kappa,0)\). For example, \(f(d)=\beta_1d+\beta_2(d-\kappa_1)_++\beta_3(d-\kappa_2)_+\) is continuous, with slopes that can differ across the knots. More flexible cubic splines are also common; their fitted coefficients are usually less interpretable individually, so contrasts are best calculated from the fitted function itself.
Worked Example: A Linear Duration Effect
Suppose a weighted Cox fit gives \(f(d)=0.08d\), where \(d\) is measured in months. Compare regimes that produce 6 and 12 months of cumulative treatment by a specified time \(t\).
The model’s log hazard contrast is \(f(12)-f(6)=0.08(12)-0.08(6)=0.96-0.48=0.48\). The hazard ratio is \(\exp(0.48)\approx1.616\). Thus, at that time, the modeled hazard under the 12-month regime is about 1.62 times the hazard under the 6-month regime, provided the model and causal assumptions hold. The same ratio applies to any pair of regimes whose cumulative durations differ by 6 months, because the linear model imposes a constant slope.
Worked Example: Duration Categories
Suppose the reference band is 0 to less than 6 months. The fitted contributions are \(\gamma_1=0.30\) for 6 to less than 12 months and \(\gamma_2=0.70\) for 12 months or more. Compare durations of 8 and 14 months.
The two durations lie in bands with contributions 0.30 and 0.70. Their log hazard contrast is \(0.70-0.30=0.40\), so the hazard ratio for 14 versus 8 months is \(\exp(0.40)\approx1.492\). This model does not distinguish 8 months from 11 months, or 14 months from 20 months: within each band, the fitted contribution is constant. That equality is an imposed feature of the model, not evidence that the durations have identical effects.
How Functional Forms Determine Hazard Contrasts
At a fixed time \(t\), compare two intervention regimes \(g_1\) and \(g_0\). If the model has the same baseline hazard under both regimes and duration is its only regime-dependent term, then the baseline cancels in the hazard ratio. This gives a direct rule for interpreting any chosen functional form.
Derivation. By the model, \(h^{g_1}(t)=h_0(t)\exp\{f(D^{g_1}(t))\}\) and \(h^{g_0}(t)=h_0(t)\exp\{f(D^{g_0}(t))\}\). For times at which the common baseline hazard is positive, divide the first expression by the second. The baseline terms cancel, leaving \(\exp\{f(D^{g_1}(t))-f(D^{g_0}(t))\}\). The expression also defines the model-based ratio by continuity when the baseline hazard is zero. \(\square\)
The result shows why “the duration hazard ratio” may be an incomplete description. Under a linear form, a specified duration difference gives the same contrast at all duration levels. Under a categorical form, the contrast depends on the bands occupied. Under a spline, it depends on the two fitted function values. And because cumulative durations can change as follow-up proceeds, even a fixed pair of regimes can have a time-varying hazard ratio.
Worked Example: Contrasts from a Piecewise-Linear Spline
Let duration be in months and suppose \(f(d)=0.04d+0.03(d-6)_+-0.02(d-12)_+\). The knots are at 6 and 12 months. Compare durations of 6, 12, and 18 months.
At 6 months, both hinge terms are zero, so \(f(6)=0.04(6)=0.24\). At 12 months, the first hinge is \(12-6=6\) and the second is zero: \(f(12)=0.04(12)+0.03(6)=0.48+0.18=0.66\). At 18 months, the hinge terms are 12 and 6, so \(f(18)=0.04(18)+0.03(12)-0.02(6)=0.72+0.36-0.12=0.96\).
The hazard ratio for 12 versus 6 months is \(\exp(0.66-0.24)=\exp(0.42)\approx1.522\). For 18 versus 12 months it is \(\exp(0.96-0.66)=\exp(0.30)\approx1.350\). The implied log-hazard slopes are 0.04 per month up to 6 months, \(0.04+0.03=0.07\) from 6 to 12 months, and \(0.04+0.03-0.02=0.05\) after 12 months. The fitted function is continuous at each knot, but the slope changes there.
Derivation. On an interval containing no knot, each hinge is either zero throughout or equals \(d-\kappa_j\) throughout. Differentiating on that interval therefore gives \(f'(d)=\beta_1+\sum_{j:\,d>\kappa_j}\beta_{j+1}\). At a knot \(\kappa_m\), its hinge is zero on the knot itself and approaches zero from either side; all other hinge terms have the same limit from both sides. Hence the left- and right-hand limits of \(f(d)\) agree at \(\kappa_m\). The slope may change, but the function does not jump. \(\square\)
Choosing and Checking a Functional Form
The form should match the scientific question and the support of the data. A linear term is economical and gives a compact interpretation per unit of duration, but it rules out curvature. Categories allow a small number of clear comparisons, but the results can depend strongly on cutpoints and discard distinctions within each band. Splines offer graded flexibility and continuity, but require choices about basis, knots, and boundary behavior. Their coefficients are not usually meaningful as stand-alone effects; report predicted contrasts at substantively useful durations instead.
Diagnostics should assess both model shape and data support. Examine the distribution of cumulative duration among weighted risk-set members, not just the unweighted baseline sample. Look for duration ranges with sparse support or very large weights: a flexible curve cannot recover information absent from the data. Compare estimated contrasts across plausible category cutpoints or spline knot choices, and inspect whether the fitted function behaves implausibly near its boundaries. Residual-based checks can also reveal systematic lack of fit, though a good-looking curve does not establish the causal assumptions.
A frequent mistake is to interpret a spline coefficient, or a category coefficient, as a universal hazard ratio. In a spline, one basis coefficient generally does not equal the contrast for a one-month increase. In a categorical model, a coefficient compares its band with the reference band, not with every other band. The correction is to calculate \(f(d_1)-f(d_0)\) for the actual durations being compared, then exponentiate that difference. Another pitfall is to treat a change in cumulative duration as a fixed treatment effect over follow-up: the regime-specific durations may diverge over time, so the implied contrast can change even if \(f\) itself does not depend explicitly on time.
Finally, flexible duration terms address only the shape of the duration contribution under the stated model. They do not repair incorrect weights, violations of positivity, unmeasured confounding, or a poor choice of exposure summary. For example, two histories can have the same total treated duration but different timing; a duration-only model assigns them the same contribution. Whether that summary is adequate is a scientific assumption, not something a spline can guarantee.
Check Your Understanding
Work through the questions, then check each result against the solutions.
- In a linear model \(f(d)=0.05d\), calculate the hazard ratio for 10 versus 4 months of cumulative treatment.
- A categorical model assigns log-hazard contributions 0 to the reference band, 0.25 to the next band, and 0.60 to the highest band. What is the hazard ratio for a duration in the highest band versus one in the next band?
- For \(f(d)=0.03d+0.02(d-5)_+\), calculate \(f(10)-f(5)\) and the corresponding hazard ratio.
- Why can the hazard ratio for the same two intervention regimes vary with follow-up time in a duration-only model?
- Give one limitation of duration categories and one limitation of a duration spline.
Solutions. 1. The log contrast is \(0.05(10)-0.05(4)=0.50-0.20=0.30\), so the hazard ratio is \(\exp(0.30)\approx1.350\). 2. The log contrast is \(0.60-0.25=0.35\), giving \(\exp(0.35)\approx1.419\). 3. \(f(5)=0.03(5)+0.02(0)=0.15\), while \(f(10)=0.03(10)+0.02(5)=0.40\). The log contrast is \(0.40-0.15=0.25\), and the hazard ratio is \(\exp(0.25)\approx1.284\). 4. Each regime can accumulate treatment at a different rate, so \(D^{g_1}(t)\) and \(D^{g_0}(t)\), and thus their difference after applying \(f\), can change with \(t\). 5. Categories treat all durations within a band as having the same modeled effect and depend on chosen cutpoints. Splines require choices such as knots and may be unstable where weighted data support is sparse.