Tutorials › Econometrics (Graduate) › Estimating GLS Variance Components by ML and REML

Generalized Least Squares · Tutorial 153 of 952

Estimating GLS Variance Components by ML and REML

Set up ML and REML for a random-intercept model, distinguish their treatment of fixed effects, and calculate variance-component estimates from grouped data.

Intermediate 12 min read

What You'll Learn

  • Specify the random-intercept model and its covariance matrix
  • Separate within-group and between-group variation in a balanced design
  • Derive the ML and REML variance estimates and explain their different denominators
  • Enforce the nonnegative variance-component constraint, including a boundary fit
  • Translate fitted variance components into the implied covariance between observations

Why Estimate Variance Components?

In generalized least squares, the covariance matrix determines how observations are weighted and how their dependence is represented. When observations in the same group share a random intercept, their covariance depends on two unknown quantities: the variance of the shared group effect and the variance of observation-specific noise. Estimating these variance components is therefore part of fitting the covariance model, not a separate choice of weights made in advance.

Maximum likelihood (ML) and restricted maximum likelihood (REML) use the same covariance model but account differently for estimating fixed effects. In a balanced random-intercept model, the distinction has a transparent expression: ML estimates a between-group variance using \(G\) dimensions, whereas REML uses \(G-1\) group contrasts after removing the overall mean. That difference can affect the fitted covariance, particularly when the number of groups is modest.

Model and Covariance Structure

Definition: For groups \(g=1,\ldots,G\), let the observations in group \(g\) satisfy \(y_{gj}=x_{gj}'\beta+b_g+\varepsilon_{gj}\), for \(j=1,\ldots,m_g\). The fixed-effect vector is \(\beta\); the group-specific random intercepts satisfy \(b_g\sim N(0,\tau^2)\); and the observation errors satisfy \(\varepsilon_{gj}\sim N(0,\sigma^2)\). Assume the random intercepts are mutually independent, the errors are mutually independent, and the two collections are independent. The variance components obey \(\tau^2\geq 0\) and \(\sigma^2>0\).

In vector notation, \(y=X\beta+Zb+\varepsilon\), so after integrating out the random intercepts, \(y\sim N(X\beta,V)\), where \(V=\tau^2ZZ'+\sigma^2I\). The matrix \(Z\) assigns each observation to its group. Two different observations in the same group have covariance \(\tau^2\); an observation has variance \(\tau^2+\sigma^2\). Observations in different groups have covariance zero under this model.

The likelihood-based calculations below use the balanced, intercept-only special case: each of \(G\) groups has \(m\) observations, and the only fixed effect is a common intercept \(\beta\). Write \(N=Gm\), and define \(\lambda=\sigma^2+m\tau^2\). This is the covariance eigenvalue in a group-constant direction; it is not the variance of an individual observation. The component constraint \(\tau^2\geq0\) is equivalent to \(\lambda\geq\sigma^2\).

Within-Group and Between-Group Variation

Let \(\bar y_g\) be the mean in group \(g\), and let \(\bar y\) be the overall mean. The data separate into deviations within groups and deviations among group means:

$$ SS_W=\sum_{g=1}^{G}\sum_{j=1}^{m}(y_{gj}-\bar y_g)^2, \qquad SS_B=m\sum_{g=1}^{G}(\bar y_g-\bar y)^2. $$

The factor \(m\) in \(SS_B\) matters: this is the sum of squares in the original \(N\)-observation space, not just the sum of squared deviations of the \(G\) group means. There are \(q=G(m-1)\) within-group directions, each with variance \(\sigma^2\), and \(G\) group-constant directions, each with variance \(\lambda\). One of those latter directions is the overall mean direction.

Worked Example: Set Up the ML and REML Likelihoods

Suppose four hypothetical groups each contain three observations. Their group means are \(7.75, 9.25, 10.75,\) and \(12.25\), and in each group the observations are one unit below its mean, at its mean, and one unit above it. The overall mean is \(10\). Thus each group contributes \(1^2+0^2+1^2=2\) to \(SS_W\), giving \(SS_W=4(2)=8\). The group-mean deviations are \(-2.25,-0.75,0.75,2.25\), so \(SS_B=3(2.25^2+0.75^2+0.75^2+2.25^2)=3(11.25)=33.75\).

Here \(G=4\), \(m=3\), \(N=12\), and \(q=4(3-1)=8\). The intercept estimate for any fixed covariance parameters is the overall mean, \(10\). After fitting that intercept, the ML log likelihood, apart from its displayed constant, is

$$ \ell_{\mathrm{ML}} =-\frac12\left[ 12\log(2\pi)+8\log(\sigma^2)+4\log(\lambda) +\frac{8}{\sigma^2}+\frac{33.75}{\lambda} \right]. $$

For REML, the overall mean direction is removed. The corresponding log likelihood is

$$ \ell_{\mathrm{REML}} =-\frac12\left[ 11\log(2\pi)+8\log(\sigma^2)+3\log(\lambda) +\frac{8}{\sigma^2}+\frac{33.75}{\lambda} \right]. $$

The contrast is visible in the coefficient of \(\log(\lambda)\): it is \(G=4\) for ML and \(G-1=3\) for REML. The quadratic contribution \(SS_B/\lambda\) is the same. These expressions also show why the two methods do not generally produce identical estimates.

ML and REML Estimates

The ML procedure maximizes the likelihood of the observations, estimating \(\beta\) along with the covariance parameters. For the balanced intercept-only model, profiling out \(\beta\) gives \(\hat\beta=\bar y\). For \(m\geq2\), when \(SS_W>0\) and \(SS_B>0\), differentiating the displayed ML log likelihood with respect to each gives the finite unconstrained interior estimates

$$ \hat\sigma^2_{\mathrm{ML,unc}}=\frac{SS_W}{G(m-1)}, \qquad \hat\lambda_{\mathrm{ML,unc}}=\frac{SS_B}{G}. $$

When \(q=G(m-1)>0\) and \(SS_W=0\), the likelihood is unbounded as \(\sigma^2\downarrow0\), so no finite ML or REML estimate exists under the strict constraint \(\sigma^2>0\). The denominator \(G\), rather than \(G-1\), in the second expression arises because the ordinary likelihood includes the determinant contribution from the overall mean direction, even though the fitted intercept makes its residual quadratic contribution zero. If these estimates satisfy \(\hat\lambda_{\mathrm{ML,unc}}\geq\hat\sigma^2_{\mathrm{ML,unc}}\), the corresponding variance-component estimates are \(\hat\tau^2_{\mathrm{ML}}=(\hat\lambda_{\mathrm{ML,unc}}-\hat\sigma^2_{\mathrm{ML,unc}})/m\) and \(\hat\sigma^2_{\mathrm{ML}}=\hat\sigma^2_{\mathrm{ML,unc}}\).

REML maximizes a likelihood formed from contrasts that eliminate the fixed effects. In this balanced case it removes the overall mean direction from the likelihood, leaving \(G-1\) between-group contrasts. Thus the displayed REML formula for \(\hat\lambda\) requires \(G\geq2\); if \(G=1\), there are no between-group contrasts and REML provides no information to estimate \(\tau^2\). For \(G\geq2\), when \(SS_W>0\) and \(SS_B>0\), the finite unconstrained interior estimates are

$$ \hat\sigma^2_{\mathrm{REML,unc}}=\frac{SS_W}{G(m-1)}, \qquad \hat\lambda_{\mathrm{REML,unc}}=\frac{SS_B}{G-1}, \qquad \hat\tau^2_{\mathrm{REML}}= \frac{\hat\lambda_{\mathrm{REML,unc}}-\hat\sigma^2_{\mathrm{REML,unc}}}{m}. $$

The different denominator is not a correction that can be applied to every ML estimate after the fact. It follows from the restricted likelihood's removal of the fixed-effect direction. In models with a general design matrix, the corresponding likelihoods are expressed using \(V\), \(X\), and the residual-forming projection; the balanced formulas above are a particularly clear special case.

Justification: In the ML log likelihood, the terms involving \(\sigma^2\) and \(\lambda\) are \(q\log(\sigma^2)+SS_W/\sigma^2\) and \(G\log(\lambda)+SS_B/\lambda\). Differentiating the first with respect to \(\sigma^2\) and setting the derivative to zero gives \(q/\sigma^2-SS_W/(\sigma^2)^2=0\), hence \(\hat\sigma^2=SS_W/q\). Differentiating the second with respect to \(\lambda\) gives \(G/\lambda-SS_B/\lambda^2=0\), hence \(\hat\lambda=SS_B/G\). For REML, only the determinant dimension for the between-group contrasts changes from \(G\) to \(G-1\), so the same differentiation gives \(\hat\lambda=SS_B/(G-1)\). These unconstrained solutions are valid component estimates only if \(\lambda\geq\sigma^2\).

Worked Example: Calculate Interior Fits by ML and REML

Use the four-group data just described. The within-group estimate under either method is \(\hat\sigma^2=8/8=1\). For ML, the between-direction estimate is \(\hat\lambda_{\mathrm{ML}}=33.75/4=8.4375\). It exceeds \(\hat\sigma^2\), so the nonnegative component constraint is satisfied. Therefore,

$$ \hat\tau^2_{\mathrm{ML}} =\frac{8.4375-1}{3} =\frac{7.4375}{3} =2.479. $$

For REML, \(\hat\lambda_{\mathrm{REML}}=33.75/3=11.25\), also greater than \(1\). Its random-intercept variance estimate is

$$ \hat\tau^2_{\mathrm{REML}} =\frac{11.25-1}{3} =\frac{10.25}{3} =3.417. $$

Thus ML gives fitted components \((\hat\sigma^2,\hat\tau^2)=(1,2.479)\), while REML gives \((1,3.417)\), in squared outcome units. The implied within-group covariance is the fitted \(\tau^2\); the fitted variance of an individual observation is \(\sigma^2+\tau^2\), which is \(3.479\) under ML and \(4.417\) under REML. These are different covariance fits to the same hypothetical data, not estimates of a causal effect.

Boundary Estimates and the Nonnegative Constraint

An unconstrained calculation can imply \(\hat\tau^2<0\), which is not an admissible variance. The fit must then be maximized subject to \(\tau^2\geq0\). In the balanced model, the boundary is \(\tau^2=0\), or equivalently \(\lambda=\sigma^2\). At that boundary, all observation directions have the same variance. The ML estimate is the residual sum of squares divided by \(N\), and the REML estimate is divided by \(N-1\):

$$ \hat\sigma^2_{\mathrm{ML,boundary}} =\frac{SS_W+SS_B}{N}, \qquad \hat\sigma^2_{\mathrm{REML,boundary}} =\frac{SS_W+SS_B}{N-1}, \qquad \hat\tau^2=0. $$

These expressions can also be obtained by setting \(\lambda=\sigma^2\) in the respective likelihoods and maximizing over the common variance. For ML the log-variance coefficient is \(q+G=N\); for REML it is \(q+G-1=N-1\). If the unconstrained estimates violate \(\lambda\geq\sigma^2\), the constrained optimum in this balanced model is at that boundary.

Worked Example: A Boundary Fit

Consider four hypothetical groups of three observations, each with values \(9,10,11\). Every group mean is \(10\), so \(SS_B=0\). Each group contributes \(2\) to within-group variation, giving \(SS_W=8\), with \(N=12\) and \(q=8\). The unconstrained estimates are \(\hat\sigma^2=8/8=1\) and \(\hat\lambda_{\mathrm{ML}}=0/4=0\), which violate \(\lambda\geq\sigma^2\). The unconstrained REML estimate of \(\lambda\) is also zero and violates the same constraint.

For ML, the constrained boundary estimate is \(\hat\sigma^2=(8+0)/12=0.6667\) and \(\hat\tau^2=0\). For REML it is \(\hat\sigma^2=(8+0)/11=0.7273\) and \(\hat\tau^2=0\). Both fits conclude that the constrained maximum lies at zero estimated random-intercept variance for these data. This does not prove that a population variance component is exactly zero; it describes the likelihood maximum under the stated model and this sample.

From Components to a Covariance Matrix

Worked Example: Interpret a Fitted Covariance Block

Suppose three hypothetical groups each have two observations. Their means are \(3,5,7\), with observations one unit below and above each mean. The overall mean is \(5\). The within-group sum of squares is \(SS_W=3(1^2+1^2)=6\), and the between-group sum of squares is \(SS_B=2[(-2)^2+0^2+2^2]=16\). Here \(G=3\), \(m=2\), and \(q=3(2-1)=3\), so \(\hat\sigma^2=6/3=2\).

The ML estimate is \(\hat\lambda=16/3=5.333\), which exceeds \(2\). Hence \(\hat\tau^2=(5.333-2)/2=1.667\). For two observations in the same group, the fitted covariance block is

$$ \widehat V_g =\hat\sigma^2 I_2+\hat\tau^2 \begin{pmatrix}1&1\\1&1\end{pmatrix} = \begin{pmatrix} 3.667&1.667\\ 1.667&3.667 \end{pmatrix}. $$

The diagonal entries are fitted observation variances, \(\hat\sigma^2+\hat\tau^2=3.667\), and the off-diagonal entries are the fitted shared-intercept covariance, \(\hat\tau^2=1.667\). The construction follows directly from the assumed covariance model.

Why the ML–REML Distinction Matters

ML and REML answer closely related but not identical likelihood questions. ML uses the likelihood of the full data and estimates fixed effects within that likelihood. REML uses information in contrasts that do not depend on the fixed effects being estimated. In the balanced random-intercept example, REML's between-group denominator is \(G-1\), reflecting removal of the overall mean direction; ML's denominator is \(G\). Neither calculation changes the assumed random-intercept structure.

REML likelihood values depend on the fixed-effect design \(X\), so they are generally not used to compare models with different fixed-effect specifications. ML likelihoods are used for such comparisons because they are based on the full data likelihood under each model. This distinction concerns likelihood comparison, not a claim that one method is universally preferable for every purpose.

Common Mistakes

  • Using the REML denominator in an ML calculation. In this balanced model, the between-group denominator is \(G\) for ML and \(G-1\) for REML. State which likelihood is being maximized before calculating.
  • Forgetting the factor \(m\) in \(SS_B\). The between-group sum of squares used with \(\lambda=\sigma^2+m\tau^2\) is \(m\sum_g(\bar y_g-\bar y)^2\).
  • Reporting a negative variance component. An unconstrained difference \((\hat\lambda-\hat\sigma^2)/m<0\) is not an admissible estimate. Refit under \(\tau^2\geq0\), including the boundary.
  • Calling \(\lambda\) the individual variance. Here \(\lambda\) is a group-constant-direction covariance eigenvalue. The individual variance is \(\sigma^2+\tau^2\).
  • Interpreting a zero boundary estimate as proof of no group variation. It is the constrained likelihood estimate for the observed data, not proof that the underlying population component equals zero.
Key takeaway: In the balanced random-intercept model, within-group variation identifies \(\sigma^2\), while between-group variation informs \(\sigma^2+m\tau^2\). ML retains the fixed-effect mean direction in its likelihood determinant; REML removes it. Always check the constraint \(\lambda\geq\sigma^2\) before translating an unconstrained fit into variance components.

Check Your Understanding

Use the model and conventions above to answer these questions.

  1. In a balanced design with \(G=6\) groups and group size \(m=4\), how many within-group directions and between-group contrast directions enter the REML likelihood?
  2. Why does the ML estimate of \(\lambda\) use denominator \(G\), while the REML estimate uses \(G-1\)?
  3. If an unconstrained estimate gives \(\hat\lambda<\hat\sigma^2\), what does this imply for \(\hat\tau^2\), and what must be done next?
  4. For two observations in the same group, identify their fitted covariance and their fitted individual variance in terms of \(\hat\tau^2\) and \(\hat\sigma^2\).
  5. Why are REML likelihood values generally unsuitable for comparing fixed-effect models with different design matrices?
Clinical Biostats