Tutorials › Model-Informed Drug Development (MIDD) › Deriving Treatment Contrasts From Longitudinal Mixed Models

Model-Based Endpoint and Sample Size Planning · Tutorial 312 of 596

Deriving Treatment Contrasts From Longitudinal Mixed Models

Learn to express a clinically defined longitudinal treatment contrast as a linear combination of mixed-model coefficients and calculate its standard error.

Advanced 11 min read

What You'll Learn

  • State the assumptions that connect a mixed model’s fixed effects to marginal means.
  • Derive a treatment contrast at a specified visit from the model’s coefficient coding.
  • Calculate the standard error of a contrast using the fixed-effect covariance matrix.
  • Combine visit-specific contrasts using prespecified weights and their full covariance.
  • Recognize diagnostics and interpretation limits for model-based contrasts.

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.

Definition: A marginal treatment contrast at visit \(k\) is the difference between the model-implied mean outcome under treatment and the model-implied mean outcome under control at that visit, after averaging over the random effects. A weighted average treatment contrast is a prespecified weighted sum of such visit-specific contrasts. If \(d_k\) denotes the treatment-minus-control contrast at visit \(k\), and \(w_k\) are weights with \(\sum_k w_k=1\), then the average is \(\theta=\sum_k w_kd_k\).

Model and Assumptions

For participant \(i\), collect the repeated outcomes in a vector \(Y_i\). A linear mixed-effects model can be written as

$$ Y_i=X_i\beta+Z_i b_i+\varepsilon_i. $$

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

$$ E(Y_{ij}\mid X_i)=\beta_0+\beta_TT_i+ \sum_{k=2}^{K}\beta_{V_k}I(v_{ij}=k)+ \sum_{k=2}^{K}\beta_{TV_k}T_iI(v_{ij}=k). $$

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

$$ \widehat{\mathrm{Var}}(c^{\mathsf T}\hat{\beta}) =c^{\mathsf T}\widehat{\mathrm{Cov}}(\hat{\beta})c, \qquad SE(c^{\mathsf T}\hat{\beta})= \sqrt{c^{\mathsf T}\widehat{\mathrm{Cov}}(\hat{\beta})c}. $$

For justification, write the contrast estimate as \(\sum_r c_r\hat{\beta}_r\). Expanding its variance gives

$$ \mathrm{Var}\left(\sum_r c_r\hat{\beta}_r\right) =\sum_r c_r^2\mathrm{Var}(\hat{\beta}_r) +2\sum_{r<s}c_rc_s\mathrm{Cov}(\hat{\beta}_r,\hat{\beta}_s) =c^{\mathsf T}\mathrm{Cov}(\hat{\beta})c. $$

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

$$ \begin{pmatrix} 0.16 & 0.04\\ 0.04 & 0.25 \end{pmatrix}. $$

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:

$$ \widehat{\mathrm{Var}}(\hat{\beta}_T+\hat{\beta}_{TV_2}) =0.16+0.25+2(0.04)=0.49, \qquad SE=\sqrt{0.49}=0.700\text{ points}. $$

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

$$ \hat{\theta}_{\mathrm{avg}}=w^{\mathsf T}\hat{\boldsymbol d}, \qquad \widehat{\mathrm{Var}}(\hat{\theta}_{\mathrm{avg}}) =w^{\mathsf T}\widehat{\Sigma}_dw. $$

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

$$ \hat{\theta}_{\mathrm{avg}} =\frac{-0.20-0.50-0.80}{3} =-0.500\text{ points}. $$

The variance of the sum of the three contrasts includes twice each pairwise covariance. Dividing by \(3^2=9\) gives

$$ \widehat{\mathrm{Var}}(\hat{\theta}_{\mathrm{avg}}) =\frac{0.25+0.36+0.49+2(0.10+0.08+0.12)}{9} =\frac{1.70}{9}=0.1889, \qquad SE=\sqrt{0.1889}=0.4346\text{ points}. $$

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

$$ \hat{\theta}_{\mathrm{avg}} =0.25(-0.20)+0.25(-0.60)+0.50(-1.00) =-0.700\text{ points}. $$

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

$$ 2\{(0.25)(0.25)(0.10)+(0.25)(0.50)(0.08)+(0.25)(0.50)(0.12)\} =2(0.00625+0.010+0.015)=0.0625. $$

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

$$ \hat{d}(12)=-0.30+12(-0.080)=-1.26\text{ points}. $$

The variance follows by applying the linear-combination formula with coefficients 1 and 12:

$$ \widehat{\mathrm{Var}}\{\hat{d}(12)\} =0.09+12^2(0.0004)+2(12)(-0.003) =0.09+0.0576-0.072=0.0756, \qquad SE=\sqrt{0.0756}=0.2750\text{ points}. $$

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.

Common pitfall: Calculating an average contrast’s variance as the weighted sum of visit-specific variances alone omits covariance terms. The correct variance is \(w^{\mathsf T}\widehat{\Sigma}_dw\). Also, a zero population mean for random effects alone does not guarantee marginal means equal the fixed-effects predictions: the required conditional mean of the random effects given the design must be zero.

Check Your Understanding

Try each problem, then compare with the solutions.

  1. 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?
  2. Two coefficient estimates have variances \(0.09\) and \(0.16\), and covariance \(0.02\). What is the variance and standard error of their sum?
  3. Two visit-specific contrasts have estimated variances \(0.25\) and \(0.36\), with covariance \(0.10\). Calculate the variance of their equal-weight average.
  4. 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.