Tutorials › Generalized Linear Mixed Models (GLMM) › Conjugate Variance Updates in Gaussian Hierarchical Models

Bayesian GLMM and Prior Specification for Variance Components · Tutorial 265 of 698

Conjugate Variance Updates in Gaussian Hierarchical Models

Learn how Gaussian random-effect assumptions and an inverse-gamma prior combine to give a closed-form conditional variance distribution.

Advanced 11 min read

What You'll Learn

  • State the hierarchical assumptions needed for a conjugate variance update.
  • Derive the full conditional under a clearly defined inverse-gamma parameterization.
  • Update a scalar random-intercept variance from realized group effects.
  • Extend the calculation to known group-specific variance multipliers and vector effects.
  • Distinguish an exact conditional update from one based on estimated random effects.
  • Diagnose common errors in counting dimensions, scaling effects, and interpreting posterior summaries.

Why a Gaussian Variance Can Have a Closed-Form Update

In a Gaussian hierarchical model, group-level effects are modeled as draws from a distribution whose spread is an unknown variance component. When the effects are treated as part of the unknown model state, their Gaussian density supplies a quadratic expression in that variance. An inverse-gamma prior has a matching form, so multiplying the prior density by the effect likelihood gives another inverse-gamma density.

The closed form depends on specific conditions: the random effects must have a Gaussian distribution with a variance proportional to the component being updated, and the prior must use the inverse-gamma parameterization stated below. This is a conditional result: it describes the distribution of the variance given the current values of the random effects and the other model quantities. It is not, by itself, a method for integrating out the random effects or a complete analysis of the marginal data likelihood.

Definition: Write \(v=\tau^2>0\) for a random-effect variance. We use the inverse-gamma parameterization \(v\sim\operatorname{IG}(a,b)\), with shape \(a>0\) and scale \(b>0\), whose density is $$ p(v)=\frac{b^a}{\Gamma(a)}v^{-(a+1)}\exp\left(-\frac{b}{v}\right),\qquad v>0. $$ Here \(b\) has the same units as \(v\). In particular, the exponential term is \(\exp(-b/v)\), not \(\exp(-bv)\).

Model and Assumptions for the Update

Consider \(J\) groups with scalar random intercepts \(u_1,\ldots,u_J\). For example, a Gaussian mixed model for a continuous outcome may be written \(y_{ij}=x_{ij}^{\mathsf T}\beta+u_j+\epsilon_{ij}\), where \(i\) indexes observations within group \(j\). For the variance update, suppose the outcome model and its parameters imply that the data likelihood depends on \(\tau^2\) only through the random effects \(u_j\). Conditional on those effects and the other parameters, the likelihood for \(\tau^2\) is therefore determined by their hierarchical distribution.

The assumptions for the basic update are:

  • Conditional on \(\tau^2\), the group effects are independent and identically distributed as \(u_j\sim N(0,\tau^2)\).
  • The inverse-gamma prior \(\tau^2\sim\operatorname{IG}(a,b)\) is independent of the other parameters before observing the data, with \(a,b>0\).
  • The update conditions on the realized effects \(u_1,\ldots,u_J\) and on the remaining parameters. The likelihood for the observed outcomes has no additional direct dependence on \(\tau^2\) once the effects are given.

These assumptions specify what is being updated. In particular, \(J\) is the number of independent group effects in this variance component—not the number of individual observations. If effects have unequal known variances, or if the component multiplies a known covariance matrix, the quadratic term must reflect that structure.

Theorem: Under the assumptions above, the full conditional distribution of the scalar random-intercept variance is $$ \tau^2\mid u_1,\ldots,u_J,\text{other quantities} \sim \operatorname{IG}\left(a+\frac{J}{2},\ b+\frac{1}{2}\sum_{j=1}^{J}u_j^2\right). $$ The posterior shape adds half the number of independent Gaussian effects, and the posterior scale adds half their sum of squares.

Derivation of the Full Conditional

The joint conditional density of the effects given \(v=\tau^2\) is the product of \(J\) normal densities. Discarding factors that do not depend on \(v\), it is proportional to \(v^{-J/2}\exp[-\sum_j u_j^2/(2v)]\). Multiplying by the inverse-gamma prior kernel gives

$$ \begin{aligned} p(v\mid u_1,\ldots,u_J,\text{other quantities}) &\propto p(u_1,\ldots,u_J\mid v)\,p(v)\\ &\propto v^{-J/2} \exp\left(-\frac{\sum_{j=1}^{J}u_j^2}{2v}\right) v^{-(a+1)}\exp\left(-\frac{b}{v}\right)\\ &=v^{-\left(a+J/2+1\right)} \exp\left[-\frac{b+\frac12\sum_{j=1}^{J}u_j^2}{v}\right]. \end{aligned} $$

This is the inverse-gamma kernel with shape \(a+J/2\) and scale \(b+\frac12\sum_j u_j^2\). Both updated parameters are positive because \(a,b>0\) and the sum of squares is nonnegative, so the kernel is normalizable. The conditional distribution is consequently proper under the stated proper prior.

Worked Example: Updating a Random-Intercept Variance

Suppose five hypothetical group effects, measured in outcome units, are \(0.4,-0.2,0.1,0.5,-0.3\). Conditional on the other model quantities, assume these effects are independent \(N(0,\tau^2)\), and use the prior \(\tau^2\sim\operatorname{IG}(2,1)\). The Gaussian model and prior assumptions match the update above.

First calculate the sum of squared effects: $$ \sum_{j=1}^{5}u_j^2 =(0.4)^2+(-0.2)^2+(0.1)^2+(0.5)^2+(-0.3)^2 =0.16+0.04+0.01+0.25+0.09=0.55. $$

There are \(J=5\) scalar effects. Thus the updated shape is \(2+5/2=4.5\), and the updated scale is \(1+0.55/2=1.275\). The full conditional is $$ \tau^2\mid u,\text{other quantities}\sim\operatorname{IG}(4.5,1.275). $$

For this parameterization, an inverse-gamma distribution with shape \(A>1\) and scale \(B\) has mean \(B/(A-1)\). Here the conditional mean is \(1.275/(4.5-1)=1.275/3.5\approx0.3643\) outcome-units squared. This is a conditional posterior summary given the stated effects and other quantities, not a marginal summary that averages over uncertainty in those effects.

Known Variance Multipliers and Vector Effects

The same calculation applies when a variance component is multiplied by a known positive quantity. Suppose independent scalar effects satisfy \(u_j\mid\tau^2\sim N(0,c_j\tau^2)\), where each \(c_j>0\) is known. Their densities contribute \((\tau^2)^{-J/2}\exp[-\sum_j u_j^2/(2c_j\tau^2)]\), apart from terms not depending on \(\tau^2\). Therefore the updated scale uses a weighted sum of squares, \(\frac12\sum_j u_j^2/c_j\), while the shape still increases by \(J/2\).

Result: If \(u_j\mid\tau^2\sim N(0,c_j\tau^2)\) independently, with known \(c_j>0\), and \(\tau^2\sim\operatorname{IG}(a,b)\), then $$ \tau^2\mid u_1,\ldots,u_J,\text{other quantities} \sim \operatorname{IG}\left(a+\frac{J}{2},\ b+\frac{1}{2}\sum_{j=1}^{J}\frac{u_j^2}{c_j}\right). $$

Worked Example: A Variance Component with Known Group Scales

Consider four hypothetical group effects \(u=(0.2,-0.3,0.4,0.1)\), in outcome units, with known multipliers \(c=(1,0.5,2,1)\). Assume independent \(u_j\mid\tau^2\sim N(0,c_j\tau^2)\) and prior \(\tau^2\sim\operatorname{IG}(3,2)\). These specified normal distributions and the positive multipliers meet the weighted-update assumptions.

The weighted sum of squares is $$ \sum_{j=1}^{4}\frac{u_j^2}{c_j} =\frac{0.04}{1}+\frac{0.09}{0.5}+\frac{0.16}{2}+\frac{0.01}{1} =0.04+0.18+0.08+0.01=0.31. $$ The updated shape is \(3+4/2=5\), and the updated scale is \(2+0.31/2=2.155\). Hence $$ \tau^2\mid u,\text{other quantities}\sim\operatorname{IG}(5,2.155). $$ The \(u_j^2\) terms are divided by their respective \(c_j\); using the unweighted sum would ignore the assumed group-specific variances and give the wrong conditional distribution.

For a vector effect \(u_j\in\mathbb{R}^K\), suppose \(u_j\mid\tau^2\sim N_K(0,\tau^2 I_K)\), independently across groups. The density for each group contributes a factor \((\tau^2)^{-K/2}\) and an exponential term involving \(\lVert u_j\rVert^2/(2\tau^2)\). There are \(JK\) scalar Gaussian coordinates, so the shape increases by \(JK/2\), while the scale adds half the total squared Euclidean norm. This is a restrictive isotropic model: all coordinates share the same variance and have zero conditional correlations. It is not a general update for an unrestricted random-effect covariance matrix.

Worked Example: Shared Variance for Two-Dimensional Effects

Suppose three hypothetical groups have two-dimensional effects \((0.2,-0.1)\), \((-0.3,0.4)\), and \((0.1,0.2)\), each coordinate measured in outcome units. Assume the six coordinates are conditionally independent \(N(0,\tau^2)\), and take \(\tau^2\sim\operatorname{IG}(1.5,0.8)\). This is the shared isotropic variance model just described.

The total squared norm is $$ \sum_{j=1}^{3}\lVert u_j\rVert^2 =(0.2^2+(-0.1)^2)+((-0.3)^2+0.4^2)+(0.1^2+0.2^2) =0.05+0.25+0.05=0.35. $$ There are \(JK=3(2)=6\) scalar coordinates. The updated shape is \(1.5+6/2=4.5\), and the updated scale is \(0.8+0.35/2=0.975\). Thus $$ \tau^2\mid u,\text{other quantities}\sim\operatorname{IG}(4.5,0.975). $$ Its conditional mean exists because the shape exceeds one, and equals \(0.975/(4.5-1)\approx0.2786\) outcome-units squared. The calculation relies on the common-variance assumption; it does not estimate separate coordinate variances or a correlation.

Interpretation, Diagnostics, and Alternatives

The updated shape and scale summarize how the prior and the currently conditioned-on effects combine. Larger squared effects increase the posterior scale, shifting the conditional distribution toward larger variances. More independent scalar effects increase the shape, which changes the distribution's concentration as well. These statements concern the conditional distribution; the variance's marginal posterior also accounts for uncertainty in the effects and other unknown quantities.

A useful diagnostic is to verify the model-to-formula match before calculating:

  • Count independent scalar Gaussian coordinates. For \(J\) scalar intercepts use \(J/2\); for \(J\) independent \(K\)-vectors with covariance \(\tau^2I_K\), use \(JK/2\).
  • Use the quadratic form implied by the covariance. With variance \(c_j\tau^2\), divide \(u_j^2\) by \(c_j\); with a more general known covariance matrix, use its corresponding inverse-covariance quadratic form.
  • Check the inverse-gamma convention. Under the density used here, the scale adds to the numerator of the exponent as \(\exp(-B/v)\).
  • Check units. The variance and inverse-gamma scale have squared outcome units, whereas a random effect has outcome units.

A frequent mistake is to substitute estimated group effects, such as empirical best predictions, into the formula and call the result the exact full conditional. The derivation conditions on the actual latent effects in the joint model. An estimate is not the same thing as conditioning on a latent effect draw; substituting it generally ignores uncertainty and does not produce the stated conditional distribution. Similarly, counting individual observations instead of random-effect coordinates overstates the shape increment.

This conjugate update is convenient when the Gaussian hierarchy and prior match its assumptions. Alternatives include using a different prior on the standard deviation, for which this inverse-gamma conditional form need not apply, or working with a marginal likelihood after integrating out effects, which yields a different calculation. Conjugacy also does not establish that the prior is substantively appropriate: prior sensitivity, especially when few groups inform a variance, remains important. Nor does a closed-form conditional alone resolve whether the hierarchical Gaussian model is adequate for the data.

Key takeaway: With Gaussian effects whose covariance is \(\tau^2\) times a known matrix, an inverse-gamma prior updates by adding half the number of Gaussian scalar coordinates to the shape and half the corresponding quadratic form to the scale. The formula is exact for the specified conditional model and latent effects.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. For \(J=8\) independent scalar effects and prior \(\operatorname{IG}(2,1)\), what is the posterior shape?
  2. Three scalar effects have values \(0.2,-0.1,0.3\), and the prior is \(\operatorname{IG}(1,0.5)\). Find the posterior scale.
  3. Why is the update not exact if the effects in the formula are replaced by estimated group effects?
  4. For five independent two-dimensional effects with covariance \(\tau^2I_2\), how much is added to the inverse-gamma shape?

Solutions. (1) The shape is \(2+8/2=6\). (2) The sum of squares is \(0.04+0.01+0.09=0.14\), so the posterior scale is \(0.5+0.14/2=0.57\). (3) The full conditional is derived by conditioning on the latent effects themselves; plug-in estimates do not account for their uncertainty and do not equal latent-effect draws. (4) There are \(5(2)=10\) scalar coordinates, so the shape increment is \(10/2=5\).

Clinical Biostats