Tutorials › Generalized Linear Mixed Models (GLMM) › Half-Normal Priors for Random-Effect Standard Deviations

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

Half-Normal Priors for Random-Effect Standard Deviations

Learn to specify a half-normal prior on a group-level standard deviation and interpret its scale, probabilities, and induced variance prior in the units of a GLMM.

Advanced 10 min read

What You'll Learn

  • Write and normalize a half-normal prior for a nonnegative random-effect standard deviation.
  • Derive its cumulative distribution, moments, and useful prior quantiles.
  • Interpret the scale parameter in the units of a GLMM random effect.
  • Transform the prior from a standard deviation to a variance with the correct Jacobian.
  • Check prior implications and identify common specification and interpretation errors.

Why Put a Prior on the Random-Effect Standard Deviation?

In a GLMM, a group-level random effect describes how groups vary around the population-level linear predictor. For a scalar random intercept, for example, the size of the standard deviation determines how much the group-specific intercepts can differ. In a Bayesian model, that standard deviation is unknown and needs a prior. A half-normal prior is one direct way to express plausible scales of variation while restricting the standard deviation to nonnegative values.

The scale parameter is consequential: it is measured in the same units as the random effect and controls the prior’s spread. It is not a hard upper bound, nor is it the prior mean. The useful question is therefore not only “What distribution is being used?” but also “What values of the random-effect standard deviation does its scale make plausible?”

Definition: A random-effect standard deviation \(\tau\) has a half-normal prior with scale \(A\), written \(\tau\sim\operatorname{HalfNormal}(A)\), if \(A>0\), \(\tau\geq 0\), and its density is $$ p(\tau\mid A)=\frac{\sqrt{2/\pi}}{A}\exp\left(-\frac{\tau^2}{2A^2}\right),\qquad \tau\geq 0. $$ The density is zero for \(\tau<0\). The scale \(A\) has the same units as \(\tau\).

Definition and Basic Properties

One way to construct this distribution is to take the absolute value of a normal random variable: if \(Z\sim N(0,A^2)\), then \(\tau=|Z|\) has the half-normal distribution. For a positive value \(\tau\), the density includes the normal density at both \(+\tau\) and \(-\tau\). Thus

$$ p(\tau\mid A)=\frac{1}{A\sqrt{2\pi}}\exp\left(-\frac{\tau^2}{2A^2}\right) +\frac{1}{A\sqrt{2\pi}}\exp\left(-\frac{\tau^2}{2A^2}\right) =\frac{\sqrt{2/\pi}}{A}\exp\left(-\frac{\tau^2}{2A^2}\right). $$

This construction also verifies normalization: the half-normal density integrates to one over \([0,\infty)\), because it collects the probability from both halves of the original symmetric normal distribution. Its cumulative distribution function, for \(t\geq 0\), is

$$ P(\tau\leq t)=2\Phi\left(\frac{t}{A}\right)-1, $$

where \(\Phi\) is the standard normal cumulative distribution function. Consequently, the \(q\) quantile, for \(0<q<1\), is \(A\Phi^{-1}((q+1)/2)\). In particular, the median is approximately \(0.6745A\), and the 95th percentile is approximately \(1.960A\). These are prior summaries, not bounds: the distribution has support over every nonnegative value.

The mean and second moment clarify what the scale does and does not mean:

$$ E(\tau\mid A)=A\sqrt{\frac{2}{\pi}}\approx 0.7979A,\qquad E(\tau^2\mid A)=A^2,\qquad \operatorname{Var}(\tau\mid A)=A^2\left(1-\frac{2}{\pi}\right). $$

Thus \(A\) is not the mean standard deviation. However, \(A^2\) is the prior mean of the variance \(v=\tau^2\). These statements refer to the prior distribution on \(\tau\); they are not claims about the posterior after observing data.

Using the Prior in a GLMM

For example, a random-intercept GLMM can be written, for groups \(j=1,\ldots,J\), as

$$ g\{E(Y_{ij}\mid b_j,\boldsymbol{x}_{ij})\} =\boldsymbol{x}_{ij}^{\mathsf T}\boldsymbol{\beta}+b_j,\qquad b_j\mid\tau\sim N(0,\tau^2),\qquad \tau\sim\operatorname{HalfNormal}(A). $$

Here the group effects are conditionally independent given \(\tau\), and the half-normal prior is on their standard deviation, not directly on each \(b_j\). The usual GLMM likelihood specifies the conditional distribution of the observations given the group effects and fixed effects. The prior above specifies uncertainty about the amount of between-group variation. Any other prior assumptions, such as dependence between \(\tau\) and fixed-effect parameters, must be stated separately; they are not implied by choosing a half-normal prior.

The scale must be interpreted in the units of \(b_j\). In a logistic random-intercept model, \(b_j\) is measured on the log-odds scale. In a log-link model, it is on the log-mean scale. For a random slope, the scale is in the units of the slope coefficient, which depend on the predictor’s units. Rescaling or centering predictors can therefore change how a random-effect scale should be understood.

Worked Example: Interpreting a Scale on the Log-Odds Scale

Suppose a hypothetical logistic random-intercept model uses \(\tau\sim\operatorname{HalfNormal}(0.4)\), where \(b_j\) and \(\tau\) are measured in log-odds units. Find the prior probability that \(\tau<0.5\), and the 95th percentile of the prior for \(\tau\).

Probability below 0.5. Substitute \(A=0.4\) and \(t=0.5\) in the half-normal cumulative distribution:

$$ P(\tau<0.5)=2\Phi(0.5/0.4)-1 =2\Phi(1.25)-1 \approx 2(0.89435)-1 =0.7887. $$

Under this prior, the probability that the group-level standard deviation is below 0.5 log-odds units is about 0.7887. This is a probability about the prior for \(\tau\), not the probability that any particular group effect is below 0.5.

95th percentile. The half-normal 95th percentile is \(A\Phi^{-1}(0.975)\), so

$$ 0.4\Phi^{-1}(0.975)\approx 0.4(1.960)=0.7840 $$

log-odds units. The prior assigns 95% probability to \(\tau\leq 0.7840\) and 5% to larger values. It does not rule out larger group-level standard deviations.

From Standard Deviation to Variance

Some model descriptions use the variance \(v=\tau^2\) rather than the standard deviation. A prior on \(\tau\) induces a prior on \(v\), but the density must be transformed. For \(v>0\), \(\tau=\sqrt{v}\) and \(d\tau/dv=1/(2\sqrt{v})\). Therefore,

$$ p(v\mid A)=p(\sqrt{v}\mid A)\left|\frac{d\tau}{dv}\right| =\frac{\sqrt{2/\pi}}{2A\sqrt{v}} \exp\left(-\frac{v}{2A^2}\right),\qquad v>0. $$

The factor \(1/(2\sqrt{v})\) is essential. A half-normal prior on \(\tau\) is not the same specification as assigning a half-normal-shaped density to \(v\). Also, a density’s numerical value depends on the variable’s units: \(p(\tau)\) has units inverse to those of \(\tau\), whereas \(p(v)\) has units inverse to those of \(v\).

Worked Example: Evaluating the Standard-Deviation and Variance Densities

Let \(\tau\sim\operatorname{HalfNormal}(0.4)\). Calculate the density at \(\tau=0.6\), then calculate the induced density for \(v=\tau^2=0.36\).

Density for \(\tau\). Substitution into the half-normal density gives

$$ p_\tau(0.6\mid 0.4) =\frac{\sqrt{2/\pi}}{0.4} \exp\left(-\frac{0.6^2}{2(0.4)^2}\right) =1.994711\exp(-1.125) \approx 0.6476. $$

Induced density for \(v\). Since \(2\sqrt{v}=2(0.6)=1.2\), the Jacobian multiplier is \(1/1.2\):

$$ p_v(0.36\mid 0.4) =p_\tau(0.6\mid 0.4)\frac{1}{2\sqrt{0.36}} =\frac{0.647588}{1.2} \approx 0.5397. $$

The two density values describe different variables and have different units. They are not probabilities at those exact values; probabilities are obtained by integrating a density over an interval.

How the Scale Changes Plausible Heterogeneity

The half-normal family is a scale family: increasing \(A\) stretches the distribution, without changing its shape. For any positive threshold \(c\),

$$ P(\tau>c)=2\left\{1-\Phi\left(\frac{c}{A}\right)\right\}. $$

This formula is a direct way to see how choices of \(A\) affect prior beliefs about large random-effect standard deviations. For fixed \(c\), increasing \(A\) increases the prior probability above \(c\). A scale should therefore be assessed against thresholds that have an interpretable meaning for the random effect in the model.

Worked Example: Comparing Two Plausible Scales

Consider two hypothetical priors for a logistic random-intercept standard deviation, measured in log-odds units: \(\operatorname{HalfNormal}(0.3)\) and \(\operatorname{HalfNormal}(0.6)\). Compare the prior probability that \(\tau>0.5\).

For \(A=0.3\),

$$ P(\tau>0.5)=2\left\{1-\Phi(0.5/0.3)\right\} =2\{1-\Phi(1.6667)\} \approx 2(1-0.9522) =0.0956. $$

For \(A=0.6\),

$$ P(\tau>0.5)=2\left\{1-\Phi(0.5/0.6)\right\} =2\{1-\Phi(0.8333)\} \approx 2(1-0.7977) =0.4047. $$

The larger scale gives about 0.4047 prior probability to standard deviations above 0.5 log-odds units, compared with about 0.0956 for the smaller scale. This difference comes from the stated priors alone; it does not show which scale is better for an application. That judgment requires considering the model’s units and what range of group heterogeneity is scientifically plausible.

Assumptions, Checks, and Alternatives

The prior is mathematically defined once \(A>0\) is specified. Its use in a GLMM also rests on the model’s chosen conditional random-effect distribution. In the random-intercept formulation above, that distribution is normal with mean zero and variance \(\tau^2\). The half-normal prior does not make nonnormal group effects appropriate, establish conditional independence of observations, or determine the likelihood. Those are distinct modeling choices that should be justified for the application.

Before fitting, check the prior on the scale that matters in the model. Useful checks include calculating a few quantiles, evaluating probabilities above meaningful thresholds, and confirming that the units of \(A\) match the random-effect coefficient. For a logit random intercept, a one-unit change in \(b_j\) changes the conditional odds by a factor of \(\exp(1)\); this provides context for assessing proposed log-odds scales. For a random slope, also check the predictor’s units and scale.

After fitting, inspect whether the posterior for \(\tau\) is concentrated in a range where the prior meaningfully affects inference, and whether posterior summaries are sensitive to reasonable changes in \(A\). Such checks do not replace checking the likelihood, the random-effect structure, or model fit. A prior can be mathematically proper and still poorly matched to the substantive scale of a problem.

SpecificationWhat it puts a prior onKey point
Half-normal priorNonnegative standard deviation \(\tau\)Its scale \(A\) is in the units of \(\tau\); it has unbounded support.
Inverse-gamma priorOften the variance \(v=\tau^2\)Its implications for \(\tau\) depend on transforming the variance prior.
Normal prior on an unrestricted \(\tau\)A real-valued parameterIt assigns probability to negative standard deviations and is not the stated half-normal model.
Half-Student-t priorNonnegative standard deviation \(\tau\)A different prior family with different tail behavior.

The half-normal prior offers a simple, proper distribution with a direct scale interpretation. Its limitations matter too: it is not a universal default, its tail decreases exponentially in \(\tau^2\), and it has no point mass at \(\tau=0\). Thus it allows values arbitrarily close to zero but does not assign positive prior probability to an exactly zero variance. Choosing it does not by itself test whether a random-effect component should be absent.

Common Mistakes

  • Treating \(A\) as the prior mean or an upper limit. The mean is \(A\sqrt{2/\pi}\), and the distribution has no finite upper endpoint.
  • Putting the prior on the wrong parameter. A half-normal prior on \(\tau\) induces the variance density through a Jacobian; it is not the same as using that density directly for \(v\).
  • Ignoring units. A scale for a log-odds random intercept is in log-odds units, while a random-slope scale depends on predictor units.
  • Interpreting a density as a probability. Values such as \(p_\tau(0.6)\) are density heights; probabilities require integration across intervals.
  • Assuming the prior validates the model. A half-normal prior does not justify the likelihood, the normal random-effect distribution, or the chosen grouping structure.
Key takeaway: A half-normal prior specifies a nonnegative random-effect standard deviation with density \(\sqrt{2/\pi}A^{-1}\exp\{-\tau^2/(2A^2)\}\). Choose and evaluate \(A\) in the units of the random effect, and use the change-of-variables Jacobian whenever expressing the prior on the variance.

Check Your Understanding

Answer each question using the half-normal definition and the stated model units.

  1. If \(\tau\sim\operatorname{HalfNormal}(0.5)\), what is \(E(\tau)\), and what is the approximate 95th percentile?
  2. For \(A=0.5\), calculate \(P(\tau<0.5)\).
  3. What Jacobian factor is required to transform a density from \(\tau\) to \(v=\tau^2\)?
  4. In a logistic random-intercept model, what units does \(A\) have, and does a half-normal prior assign positive probability to \(\tau=0\) exactly?

Solutions. (1) \(E(\tau)=0.5\sqrt{2/\pi}\approx 0.3989\). The 95th percentile is \(0.5\Phi^{-1}(0.975)\approx 0.9800\). (2) \(P(\tau<0.5)=2\Phi(1)-1\approx 0.6827\). (3) Since \(\tau=\sqrt{v}\), the factor is \(\left|d\tau/dv\right|=1/(2\sqrt{v})\). (4) \(A\) is in log-odds units. The continuous half-normal distribution assigns probability zero to the single point \(\tau=0\); it allows values arbitrarily close to zero but has no point mass there.

Clinical Biostats