From a Longitudinal Model to a Treatment Contrast
A longitudinal model can estimate treatment differences at several visits while accounting for repeated observations within each participant. But the model’s coefficients are not always the treatment effects a study aims to report. With treatment-by-visit interactions, for example, the treatment difference changes over time and must be formed from more than one coefficient. An average across visits requires another step: combine the visit-specific differences with explicit weights and use their covariances to calculate precision.
The target contrast should be specified before it is calculated. Consistent with the earlier material on aligning estimands with model-based endpoint contrasts, the selected visits, treatment comparison, and any averaging weights need to represent the intended clinical question.
Model and Assumptions
For participant \(i\), collect the repeated outcomes in a vector \(Y_i\). A linear mixed-effects model can be written as
Here, \(X_i\) contains the fixed-effect design variables, \(\beta\) is the vector of fixed-effect coefficients, \(Z_i\) is the random-effect design matrix, and \(b_i\) is the participant-specific random-effect vector. The residual vector is \(\varepsilon_i\). For the usual marginal interpretation, assume the design and covariates are exogenous with respect to the random effects and residuals: in particular, \(E(b_i\mid X_i)=0\) and \(E(\varepsilon_i\mid X_i)=0\). These conditions imply \(E(Y_i\mid X_i)=X_i\beta\). Merely assuming \(E(b_i)=0\) is not sufficient if random effects are associated with the design.
For model-based standard errors, a common specification is \(b_i\sim N(0,G)\), \(\varepsilon_i\sim N(0,R_i)\), with \(b_i\) independent of \(\varepsilon_i\), and observations from different participants independent. Then \(Y_i\mid X_i\) has covariance \(V_i=Z_iGZ_i^{\mathsf T}+R_i\). The covariance structure must be appropriate enough for the fitted model to estimate uncertainty reliably. The mean contrast can still be written as a fixed-effect contrast, but a misspecified covariance structure may make its standard error and interval unreliable.
A convenient fixed-effect specification for \(K\) categorical visits uses visit 1 as the reference. Let \(T_i=1\) for treatment and \(T_i=0\) for control, and let \(I(v_{ij}=k)\) indicate visit \(k\). Omitting other covariates for clarity, the mean model is
At visit 1, the treatment-minus-control difference is \(\beta_T\). At visit \(k>1\), it is \(\beta_T+\beta_{TV_k}\): the visit main effect is shared by the two treatment groups and cancels in the difference. This is a marginal mean contrast over the random effects, conditional on any fixed covariates included in the model. If treatment effects vary with covariates, a population-average contrast also requires averaging the model predictions over a specified target covariate distribution.
Why the Covariance Matrix Determines Precision
Let \(\hat{\beta}\) be the estimated fixed-effect vector and let \(\widehat{\mathrm{Cov}}(\hat{\beta})\) be its estimated covariance matrix. Any contrast that is linear in the fixed effects can be written \(c^{\mathsf T}\beta\), where \(c\) is a vector of coefficients. Its estimate is \(c^{\mathsf T}\hat{\beta}\), and its estimated variance and standard error are
For justification, write the contrast estimate as \(\sum_r c_r\hat{\beta}_r\). Expanding its variance gives
The covariance terms matter: coefficient estimates, and contrasts from different visits, are generally not independent. Under a correctly specified linear model with known \(V_i\), the generalized least-squares estimator is \(\hat{\beta}=(X^{\mathsf T}V^{-1}X)^{-1}X^{\mathsf T}V^{-1}Y\), with covariance \((X^{\mathsf T}V^{-1}X)^{-1}\). In practice, covariance parameters are estimated, so software typically reports an estimated fixed-effect covariance matrix; finite-sample degrees-of-freedom methods may also be used. A normal-based 95% interval is approximately estimate \(\pm1.96SE\) when that approximation is suitable.
Worked Example: Contrast at a Fixed Visit
Hypothetical data. In a two-visit study, the fitted model uses visit 1 as reference. The estimated treatment coefficient is \(\hat{\beta}_T=-1.20\) points, and the estimated treatment-by-visit-2 coefficient is \(\hat{\beta}_{TV_2}=-0.80\) points. Their estimated covariance matrix, in the order \((\hat{\beta}_T,\hat{\beta}_{TV_2})\), is
At visit 1, the contrast is \(\hat{\beta}_T=-1.20\) points, with \(SE=\sqrt{0.16}=0.400\) points. At visit 2, the contrast is \(\hat{\beta}_T+\hat{\beta}_{TV_2}\), so its estimate is \(-1.20-0.80=-2.00\) points. Its variance includes both coefficient variances and their covariance:
Using the normal approximation, the visit-2 95% interval is \(-2.00\pm1.96(0.700)=[-3.372,-0.628]\) points. Under the model and approximation, this interval describes uncertainty about the visit-2 mean treatment difference. A negative difference means a lower model-implied mean in the treatment group, which is beneficial only if lower scores are clinically preferable.
Averaging Contrasts Across Visits
An across-visit contrast is not automatically the arithmetic mean. The weights define which visits contribute and in what proportion; they should be specified to match the target summary. If \(\hat{\boldsymbol d}\) is the vector of estimated visit-specific contrasts, \(w\) is the weight vector, and \(\widehat{\Sigma}_d\) is the estimated covariance matrix of those contrasts, then
The diagonal entries of \(\widehat{\Sigma}_d\) are visit-specific contrast variances; its off-diagonal entries are covariances between contrasts at different visits. Ignoring the off-diagonal terms is justified only if those covariances are zero, not simply because the contrasts refer to different visits.
Worked Example: Equal-Weight Average Across Three Visits
Hypothetical data. Suppose three visit-specific treatment contrasts are estimated as \(-0.20\), \(-0.50\), and \(-0.80\) points. Their estimated variances are \(0.25\), \(0.36\), and \(0.49\) points squared. The covariances for visit pairs 1–2, 1–3, and 2–3 are \(0.10\), \(0.08\), and \(0.12\) points squared. For an equal-weight average, each weight is \(1/3\), and the estimated contrast is
The variance of the sum of the three contrasts includes twice each pairwise covariance. Dividing by \(3^2=9\) gives
The normal-based 95% interval is \(-0.500\pm1.96(0.4346)=[-1.352,0.352]\) points. The interval includes zero; it does not establish a nonzero average difference at the corresponding two-sided 5% level under the normal approximation. It is an interval for this prespecified equal-weight summary, not a claim that the treatment difference was constant at every visit.
Worked Example: A Prespecified Unequal-Weight Average
Hypothetical data. Use the same three-visit covariance entries as above, but choose weights \(0.25\), \(0.25\), and \(0.50\), giving the third visit half the total weight. Suppose the visit-specific estimates are \(-0.20\), \(-0.60\), and \(-1.00\) points. The weighted estimate is
The diagonal contribution to its variance is \(0.25^2(0.25)+0.25^2(0.36)+0.50^2(0.49)=0.015625+0.0225+0.1225=0.160625\). The covariance contribution is
Thus, the total variance is \(0.160625+0.0625=0.223125\) points squared, and \(SE=\sqrt{0.223125}=0.4724\) points. The normal-based 95% interval is \(-0.700\pm1.96(0.4724)=[-1.626,0.226]\) points. This differs from the equal-weight result because both the target average and its precision depend on the weights.
Continuous Time, Diagnostics, and Limitations
With continuous time, the same contrast principle applies, but the visit-specific contrast depends on the chosen time value and the assumed time function. For example, a model with treatment and treatment-by-time terms has a treatment difference \(\beta_T+t\beta_{Tt}\) at time \(t\). That expression is a model-based consequence of the specified linear time trend, not a guarantee that the true treatment difference changes linearly.
Worked Example: Contrast at a Continuous-Time Assessment
Hypothetical data. Suppose time is measured in weeks, \(\hat{\beta}_T=-0.30\) points, and \(\hat{\beta}_{Tt}=-0.080\) points per week. Their estimated variances are \(0.09\) points squared and \(0.0004\) points squared per week squared, and their covariance is \(-0.003\) points squared per week. At week 12, the estimated difference is
The variance follows by applying the linear-combination formula with coefficients 1 and 12:
The normal-based 95% interval is \(-1.26\pm1.96(0.2750)=[-1.799,-0.721]\) points. This calculation is conditional on the linear time specification being an adequate description over the interval of interest.
Several checks help identify problems before interpreting a contrast:
- Check the coefficient coding. Confirm the reference treatment, reference visit, units, and contrast direction. A reversed subtraction changes the sign.
- Check the target weights. Verify that averaging weights sum to one and correspond to the intended visits and target population.
- Check the covariance calculation. The contrast variance must use the full covariance matrix, including pairwise terms. A negative covariance can reduce the variance; it should not be silently removed.
- Check model fit and assumptions. Residual patterns, implausible fitted trajectories, convergence warnings, or covariance estimates at problematic boundaries may indicate that the mean or covariance specification needs review. Estimated standard errors rely on that specification.
- Check the scope of inference. A model-based marginal mean averages over random effects under the stated exogeneity conditions. It does not automatically average over covariates or missing outcomes in the target population.
An alternative is to fit separate models at each visit or to report visit-specific contrasts without an across-visit summary. Those approaches can make visit-level results direct, but separate analyses do not automatically use the repeated-measure structure jointly and may not answer a prespecified average-contrast question. A longitudinal model offers a coherent set of means and covariances, but its contrast inherits the model’s assumptions. In particular, a poorly chosen time trend, incorrect covariance structure, or unsupported extrapolation can make a precisely calculated contrast misleading. A standard error quantifies uncertainty under the fitted model; it does not measure uncertainty about whether the model itself is correct.
Check Your Understanding
Try each problem, then compare with the solutions.
- In a model with visit 1 as reference, what is the treatment difference at visit 3 if \(\beta_T\) and \(\beta_{TV_3}\) are the treatment and treatment-by-visit-3 coefficients?
- Two coefficient estimates have variances \(0.09\) and \(0.16\), and covariance \(0.02\). What is the variance and standard error of their sum?
- Two visit-specific contrasts have estimated variances \(0.25\) and \(0.36\), with covariance \(0.10\). Calculate the variance of their equal-weight average.
- Why is \(E(b_i)=0\) alone insufficient to conclude that the marginal mean is \(X_i\beta\)?
Solutions. (1) The visit-3 difference is \(\beta_T+\beta_{TV_3}\), because the common visit effect cancels between treatment groups. (2) The variance is \(0.09+0.16+2(0.02)=0.29\), so the standard error is \(\sqrt{0.29}=0.5385\). (3) The equal-weight average has variance \([0.25+0.36+2(0.10)]/4=0.81/4=0.2025\). (4) The unconditional mean can be zero even when \(b_i\) is associated with the design. The marginal mean requires \(E(b_i\mid X_i)=0\) (as well as a zero conditional residual mean), or an equivalent condition ensuring the random-effect and residual contributions have conditional mean zero.