Skip to contents

Background

Suppose we have data from a randomized clinical trial comparing treatment groups. After fitting a particular MMRM, one must then commonly answer the question: what is the mean value of the outcome variable in each treatment group?

One method to answer this question is to use G-computation to estimate the marginal means of each treatment group. In this section, we describe the G-computation estimator in the context of the MMRM and a corresponding approach to variance estimation.

G-Computation Estimator

There are JJ treatment groups, mm planned timepoints, and nn total subjects. Define xtji=Xti(j)1×p, x_{tji} = X_{ti}(j) \in \mathbb{R}^{1 \times p}, as the row of the design matrix corresponding to subject ii, evaluated at timepoint tt if the subject had received treatment jj. In practice, this means that the design matrix columns corresponding to the treatment variable are set to the appropriate values for treatment jj - even when the subject actually received a different treatment in the trial.

The G-computation estimator of the mean outcome at time tt under treatment jj is θ̂tj=1ni=1nxtjiβ̂,j=1,,J. \hat{\theta}_{tj} = \frac{1}{n}\sum_{i=1}^n x_{tji}\,\hat{\beta}, \qquad j = 1,\dotsc,J. Collect these into the vector θ̂t=(θ̂t1,,θ̂tJ)J\hat{\theta}_t = (\hat{\theta}_{t1},\dotsc,\hat{\theta}_{tJ})^\top \in \mathbb{R}^J. Treatment effects can then be defined by linear contrasts or other functions of θ̂t\hat{\theta}_t.

Covariance Estimator of θ̂t\hat{\theta}_t

The covariance matrix of θ̂t\hat{\theta}_t can be decomposed using the law of total variance as: Var(θ̂t)=E[Var(θ̂t|X)]+Var[E(θ̂t|X)] \text{Var}(\hat{\theta}_t) = \text{E}[ \text{Var}(\hat{\theta}_t~|~X) ] + \text{Var}[\text{E}(\hat{\theta}_t~|~ X)]

Many variance estimators focus only on the first term. To enable a more general correct variance estimator that is robust to model misspecification, we need to add back the second term, which is related to the randomness of baseline covariates used in the design matrix.

To account for the extra source of variation from treating baseline covariates as random, define the vector of subject-level contributions to the G-computation estimator at time tt, 𝐯̂i=(xt1iβ̂xtJiβ̂)J,i=1,,n, \hat{\mathbf{v}}_i = \begin{pmatrix} x_{t1i}\,\hat\beta \\ \vdots \\ x_{tJi}\,\hat\beta \end{pmatrix} \in \mathbb{R}^J, \qquad i = 1,\ldots,n, with sample mean 𝐯=n1i=1n𝐯̂i\bar{\mathbf{v}} = n^{-1}\sum_{i=1}^n \hat{\mathbf{v}}_i and sample covariance Σ̂v=1n1i=1n(𝐯̂i𝐯)(𝐯̂i𝐯). \hat{\Sigma}_v = \frac{1}{n-1}\sum_{i=1}^n \left(\hat{\mathbf{v}}_i - \bar{\mathbf{v}}\right) \left(\hat{\mathbf{v}}_i - \bar{\mathbf{v}}\right)^\top.

Then if Ω̂θ\hat{\Omega}_{\theta} is the covariance estimator derived from the model while treating baseline variables as fixed (i.e. an estimate of the first term above), the overall covariance estimator that is robust to model misspecification is Ω̂c=Ω̂θ+1nΣ̂v. \hat{\Omega}_c = \hat{\Omega}_{\theta} + \frac{1}{n} \hat{\Sigma}_v.

Implementation

The G-computation estimator and corresponding covariance can be implemented using the emmeans package. To enable correct variance estimation, there is an argument emmeans_gcomp_vars in mmrm_control() that captures which variables can be treated as fixed or non-random. For example, since every subject is predicted from the model at the same time point and under each treatment, a model including TRTP and AVISIT could include emmeans_gcomp_vars = c("TRTP", "AVISIT").

Using emmeans with option weights = "proportional" and passing in the data with rows for every subject and timepoint can produce θ̂tj\hat{\theta}_{tj}.

Using

emmeans(fit, ~TRTP | AVISIT, weights = "proportional", data = data)

the emmeans function will create a linear combination matrix LglobalL^{\text{global}}. For example, the row k=(t1)J+jk=(t-1)J + j of this matrix is Lkglobal=1ni=1nxtji L^{\text{global}}_k = \frac{1}{n} \sum_{i=1}^n x_{tji}^{\top} and the G-computation estimate is Lglobalβ̂L^{\text{global}} \hat{\beta}. Using the model-trusting variance, emmeans calculates the coefficients covariance estimate V̂\hat{V} using vcov() and subsequently calculates LglobalV̂Lglobal L^{\text{global}} \hat{V} L^{\text{global}\top} as the model-trusting covariance of the G-computation estimator.

To work with emmeans functionality, we create a model-robust coefficients covariance estimate V̂c\hat{V}_c such that LglobalV̂cLglobal=Ω̂c=LglobalV̂Lglobal+S. L^{\text{global}} \hat{V}_c L^{\text{global}\top} = \hat{\Omega}_c = L^{\text{global}} \hat{V} L^{\text{global}\top} + S. where SS is a block-diagonal matrix corresponding to the relevant empirical covariance 1nΣ̂v\frac{1}{n} \hat{\Sigma}_v at each time point.

This turns out to involve solving a linear system V̂c=V̂+Lglobal(LglobalLglobal)S(LglobalLglobal)Lglobal, \hat{V}_c = \hat{V} + L^{\text{global}\top} (L^{\text{global}} L^{\text{global}\top})^{-} S (L^{\text{global}} L^{\text{global}\top})^{-} L^{\text{global}}, where ZZ^- represents the Moore-Penrose inverse of ZZ.