Here we describe the exact model definition as well as the estimation
algorithms in detail. After reading through this vignette, you can
follow the implementation of the algorithm in mmrm.cpp
and
the covariance structures in covariance.h
in the
src
directory of this package.
Model definition
The mixed model for repeated measures (MMRM) definition we are using in this package is the following. Let denote the subjects from which we observe multiple observations from total time points . Note that the number of time points for a specific subject, , can be smaller than , when only a subset of the possible time points have been observed.
Linear model
For each subject we observe a vector and given a design matrix and a corresponding coefficient vector we assume that the observations are multivariate normal distributed: where the covariance matrix is derived by subsetting the overall covariance matrix appropriately by where the subsetting matrix contains in each of its columns contains a single 1 indicating which overall time point is matching . Each row contains at most a single 1 but can also contain only 0 if this time point was not observed. For example, assume a subject was observed on time points out of total then the subsetting matrix is is the diagonal weight matrix, which is the identity matrix if no weights are specified. Note that this follows from the well known property of the multivariate normal distribution that linear combinations of the random vector again have a multivariate normal distribution with the correspondingly modified mean vector and covariance matrix.
Conditional on the design matrices , the coefficient vector and the covariance matrix we assume that the observations are independent between the subjects.
We can write the linear model for all subjects together as where combines all subject specific observations vectors such that we have in total observations, combines all subject specific design matrices and has a multivariate normal distribution where is block-diagonal containing the subject specific covariance matrices on the diagonal and 0 in the remaining entries.
Covariance matrix model
The symmetric and positive definite covariance matrix is parametrized by a vector of variance parameters . There are many different choices for how to model the covariance matrix and correspondingly has different interpretations. Since any covariance matrix has a unique Cholesky factorization where is the lower triangular Cholesky factor, we are going to use this below.
Unstructured covariance matrix
The most general model uses a saturated parametrization, i.e. any covariance matrix could be represented in this form. Here we use where is the diagonal matrix of standard deviations, and is a unit diagonal lower triangular matrix. Hence we start with the natural logarithm of the standard deviations, followed by the row-wise filled entries of : Here has entries. For example for time points we need variance parameters to model the unstructured covariance matrix.
Other covariance matrix choices are explained in the covariance structures vignette.
Grouped covariance matrix
In some cases, we would like to estimate unique covariance matrices across groups, while keeping the covariance structure (unstructured, ante-dependence, Toeplitz, etc.) consistent across groups. Following the notations in the previous section, for subject in group , we have
where is the group of subject and is the covariance matrix of group .
The parametrization of is similar to other non-grouped . Assume that there are total number of groups, the length of is multiplied by , and for each part, is parametrized in the same fashion. For example, for an unstructured covariance matrix, has entries.
Spatial covariance matrix
A spatial covariance structure can model individual-specific visit times. An individual’s covariance matrix is then a function of both the population-level covariance parameters (specific to the chosen structure) and the individual’s visit times. Following the notations in the previous section, for subject with total number of visits, we have
The element of is a function of the distance between and visit occurring on and . is the coordinate(time) of visit for subject . is the constant variance. Usually we use Euclidean distance.
Currently only spatial exponential covariance structure is implemented. For coordinates with multiple dimensions, the Euclidean distance is used without transformations.
Maximum Likelihood Estimation
Given the general linear model above, and conditional on
,
we know that the likelihood for
is
and we also know that the maximum
likelihood (ML) estimate of
is the weighted least squares estimator
solving the estimating equation
Plugging in
into the likelihood above gives then the value of the function we want
to maximize with regards to the variance parameters
.
Practically this will be done on the negative log scale:
The objective function
is then minimized with numerical optimizers utilizing
quasi-Newton-Raphson algorithms based on the gradient (or additionally
with Hessian, see optimizer).
Here the use of the Template Model Builder package TMB
is
helpful because
-
TMB
allows to perform the calculations in C++, which maximizes the speed. -
TMB
performs automatic differentiation of the objective function with regards to the variance parameters , so that gradient and Hessian do not have to be approximated numerically or coded explicitly.
Weighted least squares estimator
Let’s have a look at the details of calculating the log likelihood above, including in particular the weighted least squares (WLS) estimator .
Starting point is the linear equation above and the observation that both the left and right hand sides can be decomposed into subject-specific terms given the block-diagonal structure of and therefore its inverse, : and similarly where is the weight matrix for subject , the inverse of its covariance matrix.
Instead of calculating this inverse explicitly, it is always better numerically to work with the Cholesky factorization and solve linear equations instead. Here we calculate the factorization . Note that in the case where , i.e. this subject has all time points observed, then and we don’t need to calculate this again because we have already , i.e. . Unfortunately, if , then we need to calculate this explicitly, as there is no way to update the Cholesky factorization for a subset operation as we have above. Given , we solve for with an efficient forward-solve, and similarly we solve for . Therefore we have and and we can thereby calculate the left and right hand sides for the WLS estimating equation. We solve this equation with a robust Cholesky decomposition with pivoting. The advantage is that we can reuse this decomposition for calculating the covariance matrix of , i.e. , by supplying the identity matrix as alternative right hand side.
Determinant and quadratic form
For the objective function we also need the log determinant of : where are the diagonal entries of the factor and we have used that
- the determinant of a block diagonal matrix is the product of the determinants of the blocks,
- the determinant of the product of matrices is the product of the determinants,
- the determinant of the transposed matrix is the same as the original one,
- the determinant of a triangular matrix is the product of the diagonal.
And finally, for the quadratic form we can reuse the weighted response vector and design matrix:
Restricted Maximum Likelihood Estimation
Under the restricted ML estimation (REML) paradigm we first obtain the marginal likelihood of the variance parameters by integrating out the remaining parameters from the likelihood. Here we have: where we note that depends on but not on and can therefore be pulled out of the integral.
Completing the square
Let’s focus now on the quadratic form in the exponential function and complete the square with regards to to obtain the kernel of a multivariate normal distribution: where we used and could early on identify as the covariance matrix of the kernel of the multivariate normal of and then later as the mean vector.
With this, we know that the integral of the multivariate normal kernel is the inverse of the normalizing constants, and thus such that the integrated likelihood is
Objective function
As objective function which we want to minimize with regards to the variance parameters we again take the negative natural logarithm It is interesting to see that computation of the REML objective function is only requiring a few additional calculations compared to the ML objective function. In particular, since we already have the matrix decomposition of , it is very easy to obtain the determinant of it.
Also here we use numeric optimization of
and the TMB
library supports this efficiently through
automatic differentiation.