Tutorials › Statistical Genetics › Maximum Likelihood for Linear Mixed Models

Linear Mixed Models in Genetics · Tutorial 501 of 989

Maximum Likelihood for Linear Mixed Models

Learn to construct and optimize a linear mixed model’s marginal likelihood while accounting for both fixed effects and genetic covariance.

Intermediate 11 min read

What You'll Learn

  • Write the marginal Gaussian likelihood from the mean design matrix and covariance matrix
  • Derive the score equations for fixed effects and smooth covariance parameters
  • Explain why the log-determinant term matters when fitting covariance parameters
  • Profile out fixed effects when maximizing the likelihood
  • Fit a genetic variance component in a small hypothetical cohort
  • Recognize when a variance likelihood has only a supremum at the boundary

Why the Marginal Likelihood Matters

A linear mixed model represents genetic similarity through covariance: individuals with related genotypes can have correlated phenotypes even after accounting for measured covariates. Maximum likelihood (ML) fits the model by asking which mean and covariance parameters make the observed phenotype vector most plausible under its marginal distribution. The covariance is therefore part of the likelihood, not merely an adjustment made after fitting the mean.

The key calculation uses the distribution of the observed data after the random genetic effects have been integrated out. This tutorial constructs that likelihood, derives its score equations, and uses them in a small hypothetical genetic example. The focus is likelihood fitting itself; the likelihood of error contrasts and its use for variance-component estimation are separate topics.

Marginal Gaussian Likelihood

Definition: Let \(y\) be an \(n\)-vector of phenotypes, \(X\) an \(n\times q\) fixed-effect design matrix, and \(\beta\) a \(q\)-vector of fixed-effect coefficients. A Gaussian linear mixed model has marginal distribution \(y\sim N(X\beta,V(\theta))\), where \(V(\theta)\) is an \(n\times n\) covariance matrix indexed by parameters \(\theta\). The likelihood is the multivariate normal density evaluated at the observed \(y\). It requires \(V(\theta)\) to be positive definite for the parameter values being considered.

For example, a genetic random effect \(u\) and residual error \(\varepsilon\) can be modeled as \(u\sim N(0,\sigma_g^2K)\) and \(\varepsilon\sim N(0,\sigma_e^2I)\), independently. Here \(K\) is a known genetic relationship matrix, \(\sigma_g^2\) is the genetic variance component, \(\sigma_e^2\) is the residual variance, and \(I\) is the identity matrix. Since \(y=X\beta+u+\varepsilon\), integrating out \(u\) and \(\varepsilon\) gives \(V=\sigma_g^2K+\sigma_e^2I\). If \(K\) is positive semidefinite and \(\sigma_e^2>0\), this \(V\) is positive definite.

Write \(r=y-X\beta\) for the residual vector. The log likelihood, including its normalizing constant, is

$$ \ell(\beta,\theta) =-\frac{1}{2}\left[n\log(2\pi)+\log|V(\theta)| +r^\mathsf{T}V(\theta)^{-1}r\right]. $$

The quadratic term measures the residual relative to its covariance: directions with greater modeled variance contribute less per unit residual. The log-determinant term, \(\log|V|\), penalizes covariance matrices that spread probability across a larger volume. Both terms depend on covariance parameters, so maximizing only the quadratic term would not be ML.

Worked Example: A One-Observation Likelihood

Suppose a single hypothetical phenotype \(y=2\), measured in standardized phenotype units, has known mean zero and distribution \(N(0,v)\), with \(v>0\) unknown. This is the one-dimensional Gaussian likelihood with no estimated fixed effects.

The log likelihood as a function of \(v\) is

$$ \ell(v)=-\frac{1}{2}\left[\log(2\pi)+\log v+\frac{2^2}{v}\right]. $$

Its score is

$$ \frac{d\ell}{dv} =\frac{1}{2}\left(\frac{4}{v^2}-\frac{1}{v}\right) =\frac{4-v}{2v^2}. $$

The score is zero at \(v=4\), positive for \(0<v<4\), and negative for \(v>4\). Thus the likelihood increases up to \(v=4\) and decreases thereafter. The ML estimate is \(\hat v=4\) standardized phenotype units squared. Substitution gives \(\ell(4)=-\tfrac12[\log(2\pi)+\log(4)+1]\), approximately \(-2.112\).

Score Equations

For a fixed covariance matrix, maximizing the log likelihood over \(\beta\) is generalized least squares. Differentiating with respect to \(\beta\) gives the fixed-effect score:

$$ \frac{\partial\ell}{\partial\beta} =X^\mathsf{T}V^{-1}(y-X\beta). $$

Setting this score to zero yields the generalized least-squares estimate at a given \(\theta\), provided \(X^\mathsf{T}V^{-1}X\) is invertible:

$$ \hat\beta(\theta) =(X^\mathsf{T}V(\theta)^{-1}X)^{-1} X^\mathsf{T}V(\theta)^{-1}y. $$

This is a conditional fit: it estimates the fixed effects for the current covariance parameters. In ML fitting, the covariance parameters must still be chosen by maximizing the likelihood after accounting for this dependence of \(\hat\beta\) on \(\theta\).

For a scalar covariance parameter \(\theta_j\), define \(V_j=\partial V/\partial\theta_j\). When \(V\) is differentiable and positive definite, the covariance-parameter score is

$$ \frac{\partial\ell}{\partial\theta_j} =-\frac{1}{2}\operatorname{tr}(V^{-1}V_j) +\frac{1}{2}r^\mathsf{T}V^{-1}V_jV^{-1}r. $$

The first term reflects the change in the log determinant; the second reflects the change in the residual quadratic form. At an interior ML solution, the relevant scores are zero. If parameters are constrained, a maximum can instead occur at the edge of the allowed parameter space, where a score need not be zero.

Why These Scores Have This Form

The score equations follow by differentiating the log likelihood while holding the other parameters fixed. The fixed-effect derivative follows from differentiating the quadratic form in \(y-X\beta\). For a covariance change \(dV\), the standard matrix differentials are \(d\log|V|=\operatorname{tr}(V^{-1}dV)\) and \(dV^{-1}=-V^{-1}(dV)V^{-1}\). Applying them to the log likelihood gives

$$ d\ell =-\frac{1}{2}\operatorname{tr}(V^{-1}dV) +\frac{1}{2}r^\mathsf{T}V^{-1}(dV)V^{-1}r. $$

Taking \(dV=V_j\,d\theta_j\) and dividing by \(d\theta_j\) gives the covariance score above. The derivation also clarifies why the determinant cannot be omitted: it contributes the entire trace term. In practice, the score equations may not have a closed-form joint solution, so numerical optimization of the likelihood is common.

Worked Example: Evaluating a Covariance Score

Consider two hypothetical phenotypes \(y=(1,3)^\mathsf{T}\), with an intercept-only mean \(X=(1,1)^\mathsf{T}\). At the covariance parameter value \(\theta=0.5\), suppose \(V(\theta)=\begin{pmatrix}3&\theta\\\theta&3\end{pmatrix}\). The eigenvalues at \(\theta=0.5\) are \(3.5\) and \(2.5\), so the covariance matrix is positive definite. The derivative matrix is \(V_\theta=\begin{pmatrix}0&1\\1&0\end{pmatrix}\).

At this covariance, the generalized least-squares estimate of the intercept is \(\hat\beta=2\), and \(r=(-1,1)^\mathsf{T}\). The inverse covariance and weighted residual are

$$ V^{-1} =\frac{1}{8.75} \begin{pmatrix}3&-0.5\\-0.5&3\end{pmatrix}, \qquad V^{-1}r= \begin{pmatrix}-0.4\\0.4\end{pmatrix}. $$

The fixed-effect score is \(X^\mathsf{T}V^{-1}r=(-0.4+0.4)=0\), as it must be at the fitted intercept. For the covariance score, the trace is \(\operatorname{tr}(V^{-1}V_\theta)=-1/8.75\approx-0.1143\). Also, with \(w=V^{-1}r=(-0.4,0.4)^\mathsf{T}\), \(w^\mathsf{T}V_\theta w=-0.32\). Therefore,

$$ \frac{\partial\ell}{\partial\theta} =-\frac{1}{2}(-0.1143)+\frac{1}{2}(-0.32) \approx -0.1029. $$

At this point, increasing \(\theta\) slightly decreases the profile log likelihood locally, since the fixed-effect score is zero and the displayed covariance score is negative. This is a local direction of change, not by itself a claim that \(\theta=0.5\) is the maximum.

Fitting a Genetic Variance Component

For a genetic mixed model, ML fitting evaluates the full marginal likelihood at candidate covariance parameters. A common strategy is to compute \(\hat\beta(\theta)\) for each candidate, substitute it into \(\ell(\beta,\theta)\), and maximize the resulting profile log likelihood over the allowed covariance parameters. “Profile” here means that the fixed effects are optimized for each covariance choice; it does not remove the determinant term or replace the marginal likelihood.

Worked Example: ML Fit for Two Related Individuals

Suppose two hypothetical individuals have standardized phenotypes \(y=(0,4)^\mathsf{T}\), with an unknown intercept \(\beta\). Let their known, hypothetical genetic relationship matrix be \(K=\begin{pmatrix}1&0.5\\0.5&1\end{pmatrix}\). Assume \(u\sim N(0,\sigma_g^2K)\), independent residuals \(\varepsilon\sim N(0,I)\), and \(y=\beta\mathbf{1}+u+\varepsilon\), where \(\mathbf{1}=(1,1)^\mathsf{T}\). The residual variance is fixed at one standardized phenotype unit squared; the genetic variance \(\sigma_g^2\geq0\) is to be estimated. The eigenvalues of \(K\) are \(1.5\) and \(0.5\), so \(K\) is positive semidefinite and \(V=\sigma_g^2K+I\) is positive definite for every allowed \(\sigma_g^2\).

For any candidate \(\sigma_g^2\), the covariance matrix has equal diagonal entries and equal off-diagonal entries. Its common-mean direction is \((1,1)^\mathsf{T}\), and its contrast direction is \((1,-1)^\mathsf{T}\). The generalized least-squares intercept is therefore the sample mean, \(\hat\beta=2\). In an orthonormal basis for these two directions, the covariance eigenvalues are \(\lambda_c=1+1.5\sigma_g^2\) for the common direction and \(\lambda_d=1+0.5\sigma_g^2\) for the contrast direction. The observed residual has zero common-direction component and squared contrast component \((4/\sqrt{2}-0/\sqrt{2})^2=8\).

After substituting \(\hat\beta=2\), the profile log likelihood is

$$ \ell_p(\sigma_g^2) =-\frac{1}{2}\left[ 2\log(2\pi)+\log(1+1.5\sigma_g^2) +\log(1+0.5\sigma_g^2) +\frac{8}{1+0.5\sigma_g^2} \right]. $$

To find an interior maximum, set its derivative to zero. With \(t=1+0.5\sigma_g^2\), the common-direction eigenvalue is \(3t-2\). Differentiating with respect to \(\sigma_g^2\) gives the equation

$$ \frac{1.5}{3t-2}+\frac{0.5}{t}-\frac{4}{t^2}=0 \quad\Longleftrightarrow\quad 3t^2-13t+8=0. $$

The roots are \(t=(13\pm\sqrt{73})/6\). Since the constraint \(\sigma_g^2\geq0\) requires \(t\geq1\), only \(t=(13+\sqrt{73})/6\approx3.5907\) is feasible. It gives \(\hat\sigma_g^2=2(t-1)\approx5.181\) standardized phenotype units squared. The derivative of the profile log likelihood is positive at the boundary \(\sigma_g^2=0\), changes sign at this feasible root, and is negative for larger \(t\); thus the root is the maximum over the allowed range. At the fit, \(\ell_p\approx-4.677\), compared with approximately \(-5.838\) at \(\sigma_g^2=0\).

This estimate is an ML fit for the specified two-person model, not evidence that the genetic variance is well determined in a sample of this size. The example illustrates the calculation: the model’s covariance structure, the fixed-effect fit, and both likelihood terms jointly determine the estimate.

Interpretation and Common Pitfalls

ML is useful because it gives a single objective for estimating fixed effects and covariance parameters under the assumed marginal distribution. In a genetic model, the relationship matrix determines how genetic variance induces covariance among individuals; the likelihood uses that pattern along with the observed phenotypes. The estimates remain conditional on the model being appropriate, including its mean structure, covariance structure, and Gaussian assumptions. An estimated covariance parameter is not, by itself, evidence of a causal genetic effect.

  • Dropping the log determinant. The reasoning “larger variance always makes residuals less costly, so choose the largest variance” ignores \(\log|V|\). The correction is to maximize the full log likelihood, including both the determinant and residual terms.
  • Treating the fixed-effect estimate as independent of covariance parameters. The GLS estimate generally changes with \(V(\theta)\). Recompute \(\hat\beta(\theta)\) at each candidate covariance value when profiling the likelihood.
  • Assuming every score-zero point is a maximum. A zero score can identify a minimum or another stationary point. Check the likelihood’s behavior and the parameter constraints, as in the worked fit.
  • Claiming a positive-variance maximum when the observation is zero. In the one-observation example, if \(y=0\), then \(\ell(v)=-\tfrac12[\log(2\pi)+\log v]\), which increases without bound as \(v\to0^+\). There is no maximizer over \(v>0\); the likelihood has a supremum approached at the boundary. The formula \(\hat v=y^2\) gives an interior maximum only when \(y\ne0\).
Key takeaway: For a Gaussian linear mixed model, ML is built from the marginal distribution \(y\sim N(X\beta,V(\theta))\). Its log likelihood includes a covariance-volume term and a covariance-weighted residual term; fixed effects can be profiled by GLS, while covariance parameters are optimized using the resulting full likelihood.

Check Your Understanding

Use the marginal likelihood and score equations to answer these questions.

  1. In a genetic mixed model with \(V=\sigma_g^2K+\sigma_e^2I\), what conditions on \(K\) and the variance parameters ensure that \(V\) is positive definite?
  2. Why does the covariance-parameter score contain a trace term as well as a residual quadratic-form term?
  3. For a fixed covariance matrix, what equation defines the generalized least-squares estimate of the fixed effects?
  4. In the two-individual example, why was the squared residual in the contrast direction 8 rather than 4?
  5. For a single observation \(y=0\) from \(N(0,v)\) with \(v>0\), does the likelihood have an interior maximum? Explain its behavior as \(v\) approaches zero.
Clinical Biostats