Tutorials › Generalized Linear Mixed Models (GLMM) › Variance Partitioning in Multilevel Models

Crossed and Nested Random Effects · Tutorial 505 of 698

Variance Partitioning in Multilevel Models

Compute and interpret how much of a model’s marginal variance is attributed to each nested or crossed random-effect level.

Advanced 12 min read

What You'll Learn

  • Define variance shares for a nested random-intercept model.
  • Calculate each level’s share from estimated variance components.
  • Extend the denominator when crossed random classifications are present.
  • Distinguish Gaussian response-scale partitioning from latent-scale partitioning in a GLMM.
  • Identify assumptions and diagnostics that matter when interpreting variance shares.
  • Explain why variance shares can change when a classification is added.

What a Variance Share Describes

A multilevel model assigns variation to sources at different levels: for example, students may differ within classes, classes may differ within schools, and schools may differ from one another. Variance partitioning expresses each modeled source as a share of the total marginal variance, at a specified scale. It is a descriptive decomposition of variation under the model; it does not measure the causal importance of a level.

The calculation is direct when the model has independent random intercepts and a residual term: add their variances to obtain the total, then divide each component variance by that total. The main interpretive care is deciding what belongs in the total. It depends on the response distribution and link, on which random effects are included, and on whether the calculation is made on the response scale or a latent scale.

Nested Random-Intercept Model

Consider a Gaussian response \(Y_{ijk}\) for observation \(i\) in class \(j\), which is nested within school \(k\). At fixed values of the predictors, write the model as

$$ Y_{ijk} = \mathbf{x}_{ijk}^{\mathsf T}\boldsymbol{\beta} + v_k + u_{jk} + e_{ijk}. $$

Here \(\mathbf{x}_{ijk}^{\mathsf T}\boldsymbol{\beta}\) is the fixed-effects mean, \(v_k\) is the school random intercept, \(u_{jk}\) is the class-within-school random intercept, and \(e_{ijk}\) is the observation-level residual. Assume that the random effects have mean zero, are mutually independent across levels and groups, and have variances \(\sigma^2_{\text{school}}\) and \(\sigma^2_{\text{class}}\). Assume also that the residuals have mean zero and variance \(\sigma^2_e\), and are independent of the random effects and of one another. These assumptions imply a common marginal variance at fixed predictor values:

$$ V_{\text{total}} = \operatorname{Var}(Y_{ijk}\mid \mathbf{x}_{ijk}) = \sigma^2_{\text{school}} + \sigma^2_{\text{class}} + \sigma^2_e. $$

The conditioning holds the fixed predictor values constant; it prevents variation in fitted fixed-effects means across different predictor values from being included in this decomposition. In an unbalanced design, observations can have different predictor values or different membership structures. The variance shares defined here describe the model components for an observation with the stated structure, not the variance of every possible population mixture of observations.

Definition: For a variance component \(\sigma^2_r\) in an additive model with total marginal variance \(V_{\text{total}}\), its variance share is $$ \pi_r = \frac{\sigma^2_r}{V_{\text{total}}}. $$ For the nested Gaussian random-intercept model, the school, class, and residual shares are respectively \(\sigma^2_{\text{school}}/V_{\text{total}}\), \(\sigma^2_{\text{class}}/V_{\text{total}}\), and \(\sigma^2_e/V_{\text{total}}\). Under the stated assumptions they are nonnegative and sum to one.

If the model is fitted to data, estimated shares substitute estimated variance components into the same formulas. For example, \(\hat{\pi}_{\text{school}}=\hat{\sigma}^2_{\text{school}}/(\hat{\sigma}^2_{\text{school}}+\hat{\sigma}^2_{\text{class}}+\hat{\sigma}^2_e)\). The resulting values are estimates, not known population quantities.

Worked Example: Partitioning Variance Across Three Nested Terms

Suppose hypothetical Gaussian-model estimates, in squared test-score points, are \(\hat{\sigma}^2_{\text{school}}=16\), \(\hat{\sigma}^2_{\text{class}}=9\), and \(\hat{\sigma}^2_e=25\). Assume the model has the independent random-intercept and residual terms just described.

First calculate the total:

$$ \hat{V}_{\text{total}} = 16 + 9 + 25 = 50\ \text{score-points}^2. $$

Then divide each component by 50:

$$ \hat{\pi}_{\text{school}} = \frac{16}{50}=0.320,\qquad \hat{\pi}_{\text{class}} = \frac{9}{50}=0.180,\qquad \hat{\pi}_e = \frac{25}{50}=0.500. $$

Under this fitted model, 32.0% of the marginal variance at fixed predictor values is attributed to differences between schools, 18.0% to differences between classes within schools, and 50.0% to observation-level residual variation. The shares add to \(0.320+0.180+0.500=1.000\). The result describes a model-based partition; it does not establish that changing schools or classes would cause a corresponding change in scores.

Why the Decomposition Works

The calculation follows from the variance of a sum. At fixed predictor values, the fixed-effects term is constant. The remaining terms are the school effect, the class effect, and the residual. For any random variables, the variance of a sum equals the sum of their variances plus twice each pairwise covariance. The model’s independence assumptions make these covariances zero, leaving the component variances to add.

$$ \begin{aligned} \operatorname{Var}(Y_{ijk}\mid\mathbf{x}_{ijk}) &= \operatorname{Var}(v_k+u_{jk}+e_{ijk})\\ &= \operatorname{Var}(v_k)+\operatorname{Var}(u_{jk})+\operatorname{Var}(e_{ijk})\\ &\quad +2\operatorname{Cov}(v_k,u_{jk}) +2\operatorname{Cov}(v_k,e_{ijk}) +2\operatorname{Cov}(u_{jk},e_{ijk})\\ &= \sigma^2_{\text{school}}+\sigma^2_{\text{class}}+\sigma^2_e. \end{aligned} $$

The last equality uses the assumed zero covariances. If random effects are correlated, or if additional random terms are correlated, their covariance contributions must be included in the total variance. In that situation, simply dividing each variance by a sum of variances need not give shares that sum to one. A decomposition then requires an explicitly chosen allocation of covariance contributions; it is not the simple independent-component partition defined above.

Worked Example: Adding a Crossed Classification

Suppose the response also depends on a crossed random intercept for item \(l\), so observations can share a school or class and can also share an item. Consider the model

$$ Y_{ijkl} = \mathbf{x}_{ijkl}^{\mathsf T}\boldsymbol{\beta} + v_k + u_{jk} + w_l + e_{ijkl}. $$

Assume the school, class, and item random intercepts are mutually independent, and independent of the residual. For hypothetical variance estimates of 16 for schools, 9 for classes, 10 for items, and 25 for residuals, all in squared response units, the total is

$$ \hat{V}_{\text{total}}=16+9+10+25=60. $$

The shares are

$$ \hat{\pi}_{\text{school}}=\frac{16}{60}=0.267,\quad \hat{\pi}_{\text{class}}=\frac{9}{60}=0.150,\quad \hat{\pi}_{\text{item}}=\frac{10}{60}=0.167,\quad \hat{\pi}_e=\frac{25}{60}=0.417. $$

Thus, at fixed predictor values, the fitted model attributes approximately 26.7% of the marginal variance to schools, 15.0% to classes, 16.7% to items, and 41.7% to residual variation. Rounding explains why the displayed values sum to 1.001 rather than exactly 1. The school and class estimates stayed the same as in the first example, but their shares decreased because adding the item variance increased the denominator. A changed share does not by itself mean that the estimated school or class variance decreased.

Crossed Classifications and the Meaning of “Level”

In a nested structure, one classification belongs within another: each class is associated with a school. In a crossed structure, an observation belongs to units from multiple classifications, such as a subject and an item. A crossed classification is not simply another lower level in a single hierarchy. When independent random intercepts for both classifications enter additively, each contributes a variance term to the marginal variance of an observation.

For example, with subject \(s\) and item \(l\), a Gaussian model might include \(a_s+b_l+e_{isl}\). If the subject effects, item effects, and residuals are independent with variances \(\sigma^2_{\text{subject}}\), \(\sigma^2_{\text{item}}\), and \(\sigma^2_e\), the observation-level total is their sum. The corresponding shares use that common denominator. This is a statement about the marginal variance of one response under the model. It does not mean that the crossed units are ordered into levels.

Membership matters. If a particular response has no membership in a random-effect classification, that component does not contribute to its linear predictor. If each observation has one membership in each of several crossed classifications, each included intercept contributes its variance under the independence assumptions. The model’s actual membership structure, not the labels used for classifications, determines which terms enter the total.

Variance Shares in Generalized Linear Mixed Models

For a non-Gaussian response, variance partitioning needs a stated scale. In a generalized linear mixed model, random effects are additive in the linear predictor, but the response-scale variance generally is not the sum of the random-effect variances and one constant residual variance. The conditional response variance can depend on the conditional mean, and the inverse link transforms variation on the linear-predictor scale.

One common option for a logistic model is a latent-scale partition. It treats the binary response as arising from a latent variable with a logistic residual variance of \(\pi^2/3\), then adds the random-intercept variances on that latent scale. This is a scale-specific convention, not a universal residual variance for all GLMMs. Other models and other definitions of response-scale variance require their own explicit calculation. Do not label a latent-scale share as a percentage of observed response variance.

Worked Example: A Logistic Model’s Latent-Scale Shares

Consider a hypothetical logistic random-intercept model with a school variance estimate of \(0.40\) and a class-within-school variance estimate of \(0.30\), in squared log-odds units. For this example, use the logistic latent-scale residual variance \(\pi^2/3\approx 3.290\). Assume the two random intercepts are independent.

The total latent-scale variance is

$$ \hat{V}_{\text{latent}} =0.40+0.30+\frac{\pi^2}{3} \approx 0.40+0.30+3.290=3.990. $$

The school and class latent-scale shares are approximately

$$ \hat{\pi}_{\text{school}}=\frac{0.40}{3.990}\approx 0.100,\qquad \hat{\pi}_{\text{class}}=\frac{0.30}{3.990}\approx 0.075. $$

The latent residual share is \(3.290/3.990\approx 0.825\); the three shares sum to approximately 1.000. The interpretation is that, under this convention, about 10.0% of the model’s latent-scale variance is attributed to schools and about 7.5% to classes. These are not percentages of variance in the observed binary outcomes. For a Poisson or other non-Gaussian model, one must not automatically use \(\pi^2/3\); the distribution, link, and chosen variance scale determine the calculation.

Assumptions, Diagnostics, and Limitations

Before reporting shares, verify what the fitted model says about variance and membership. In the simple additive calculation, the relevant random effects must have finite variances, and covariance terms must be zero. The Gaussian example additionally assumes a residual variance that is constant across observations. For GLMMs, specify the scale and the convention used for any distribution-specific residual term.

  • Check the model structure. Confirm which classifications are nested and which are crossed, and whether every observation has the memberships implied by the formula. Omitting a genuine random classification can assign its variation to another component or to residual variation.
  • Inspect estimated components and uncertainty. Variance estimates can be near zero or at the boundary of their parameter space. Because a share is a ratio involving several estimated quantities, uncertainty in the components affects uncertainty in the share. A point estimate alone does not show how precise the partition is.
  • Check distributional and residual assumptions. For a Gaussian model, look for substantial departures from the assumed residual behavior or clear differences in residual spread. For a GLMM, assess fit on the model’s response and link scales using diagnostics appropriate to that distribution. A poor mean or variance model weakens the meaning of its partition.
  • Consider dependence not represented in the formula. If random effects have covariance, or if residual dependence remains after accounting for the specified terms, the independent-component sum is not justified. Revisit the model rather than interpreting the simple shares mechanically.

Variance shares also depend on the selected model. Adding a random term changes the denominator, and refitting can change the estimated values of existing components as well. Shares therefore should not be compared across models as if their numerators, denominators, and scales were automatically the same. Nor do shares rank interventions: a small variance component may still matter for a particular scientific decision, and a large component is not evidence that its source is manipulable.

A variance partition is different from a reduction in variance relative to a reference model. The former allocates a specified model’s total variance among its components; the latter compares models or predictions under a chosen definition of explained variation. State which quantity is being reported. For non-Gaussian models especially, a result without its scale and convention is incomplete.

Common Pitfall

Common mistake: “The school variance estimate is unchanged, so the school’s share must also be unchanged.” The correction is that the share is a ratio. If other components are added to the total, a fixed school variance can represent a smaller share. Conversely, a share can change because its numerator changed, its denominator changed, or both.

A second frequent error is treating all GLMM shares as observed-response percentages. That is only justified if the chosen decomposition is defined on the response scale and correctly accounts for the response distribution and model. A latent-scale calculation, such as the logistic example above, must be reported as latent-scale.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. A nested Gaussian model has hypothetical estimates \(\hat{\sigma}^2_A=12\), \(\hat{\sigma}^2_B=8\), and \(\hat{\sigma}^2_e=20\), with independent components. Find the total and each share.
  2. A crossed random-intercept variance of 5 is added to the model in Question 1, while the original estimates are held fixed. What is the new share for level A, and why did it change?
  3. Why does the variance decomposition omit variation in fitted means across different predictor values?
  4. A logistic model reports a 12% school share using the latent residual variance \(\pi^2/3\). Is it correct to say that schools account for 12% of the observed binary-outcome variance? Explain.

Solutions. (1) The total is \(12+8+20=40\). The shares are \(12/40=0.300\), \(8/40=0.200\), and \(20/40=0.500\). (2) The new total is \(40+5=45\), so the A share is \(12/45\approx0.267\). It decreases because the denominator increased while its numerator stayed fixed. (3) The calculation conditions on fixed predictor values, making the fitted fixed-effects mean constant; it partitions the remaining random variation. (4) No. The 12% is a share on the specified latent scale, not a percentage of variance in observed binary outcomes.

Clinical Biostats