Algorithm Search⌘K

Modelcore

Hierarchical Bayesian model

Also called multilevel Bayesian model, Bayesian hierarchical model.

A model whose group parameters share a prior with its own hyperparameters, so groups borrow strength from each other and estimates shrink toward the common mean.

A hierarchical Bayesian model has parameters in levels. Each group jj of data has its own parameter θj\theta_j; the θj\theta_j are drawn from a common distribution with a hyperparameter ϕ\phi; and ϕ\phi has a prior of its own. Because the groups share ϕ\phi, the data of every group inform the estimate of every other group, and each estimate is pulled toward the common center by an amount that the data decide. This partial pooling lies between fitting each group alone and treating all groups as one.

The machine

There are JJ groups with data y1,…,yJy_1, \ldots, y_J. The model has three levels:

yj∣θj∼f(yj∣θj) independently,θj∣ϕ∼g(θj∣ϕ) i.i.d.,ϕ∼p(ϕ).y_j \mid \theta_j \sim f(y_j \mid \theta_j) \ \text{independently}, \qquad \theta_j \mid \phi \sim g(\theta_j \mid \phi) \ \text{i.i.d.}, \qquad \phi \sim p(\phi).

The joint density is p(ϕ)∏jg(θj∣ϕ) f(yj∣θj)p(\phi)\prod_j g(\theta_j \mid \phi)\, f(y_j \mid \theta_j), and the posterior p(θ,ϕ∣y)p(\theta, \phi \mid y) is proportional to it. More levels (students in classes in schools) and covariates at any level (a regression for the mean of gg) fit the same pattern.

Why this prior. Before the data, the groups are exchangeable: nothing tells them apart, so the joint prior of (θ1,…,θJ)(\theta_1, \ldots, \theta_J) is symmetric. By de Finetti's theorem, an exchangeable sequence that can be extended without limit is a mixture of i.i.d. sequences, and the mixing variable is ϕ\phi. So the second level is not an extra assumption, only a choice of form for the mixture.

The normal model. The main example, used below, is

yj∣θj∼N(θj,σj2) (σj known),θj∣μ,τ∼N(μ,τ2),p(μ,τ)∝p(τ).y_j \mid \theta_j \sim N(\theta_j, \sigma_j^2) \ (\sigma_j \text{ known}), \qquad \theta_j \mid \mu, \tau \sim N(\mu, \tau^2), \qquad p(\mu, \tau) \propto p(\tau).

Here yjy_j is the estimate from group jj and σj\sigma_j its standard error, as in a random effects meta-analysis.

Conditions. The model needs exchangeability of the groups given the covariates that are in the model, and a posterior that is proper. If the hyperprior is improper, propriety must be checked; the last known result below shows that the common prior p(τ)∝1/τp(\tau) \propto 1/\tau fails.

What it counts

  • The group parameters. The posterior of each θj\theta_j, its mean, its credible interval and the posterior probability that one group is ahead of another.
  • The population. The posterior of ϕ\phi, for example the center μ\mu and the spread τ\tau of the group effects.
  • A new group. The predictive law of θJ+1\theta_{J+1} and of its data, ∫g(θJ+1∣ϕ) p(ϕ∣y) dϕ\int g(\theta_{J+1} \mid \phi)\, p(\phi \mid y)\, d\phi, which a model without the second level cannot give.
  • Model checks and comparisons. Posterior predictive checks at either level, and the marginal likelihood ∫p(ϕ)∏j∫f(yj∣θj)g(θj∣ϕ) dθj dϕ\int p(\phi)\prod_j \int f(y_j \mid \theta_j) g(\theta_j \mid \phi)\, d\theta_j\, d\phi.

With conjugate choices at each level, Gibbs sampling draws each block from its full conditional in closed form. In general, Hamiltonian Monte Carlo is used, usually in the non-centred form below.

Relation to other models

  • Complete pooling and no pooling. In the normal model, τ=0\tau = 0 forces all θj=μ\theta_j = \mu, one parameter for all groups. τ→∞\tau \to \infty makes the groups unrelated, and each θj\theta_j is estimated by yjy_j alone. The hierarchical model estimates τ\tau and so chooses between the two from the data.
  • Empirical Bayes. Fixes ϕ\phi at an estimate ϕ^\hat\phi, usually by maximizing the marginal likelihood, and then uses p(θ∣y,ϕ^)p(\theta \mid y, \hat\phi). The full model integrates over ϕ\phi instead. The answers agree when JJ is large; with few groups the plug-in hides the uncertainty in ϕ\phi, and the eight schools below are a case where τ^=0\hat\tau = 0.
  • James-Stein estimator. For equal σj\sigma_j and μ=0\mu = 0, the posterior mean with τ2\tau^2 estimated from the data is a James-Stein type estimator, and its frequentist risk results apply to the shrinkage that this model does.
  • Linear mixed model. The same structure with the group effects as random effects and a regression at the first level. The frequentist analysis estimates the variance components by REML and predicts the effects; the Bayesian analysis puts a prior on them.
  • Bayesian linear regression. Lindley and Smith (1972) wrote the normal linear model with normal priors in stages, which is a hierarchical model with a linear second level.
  • Shrinkage priors. A horseshoe prior is a hierarchical model with one local scale per coefficient and a global scale; there the aim is sparsity rather than pooling.

Known results in the model

All results are for the normal model with a flat prior on μ\mu, unless stated.

1. The group parameters given the hyperparameters. Given μ\mu and τ>0\tau > 0, the θj\theta_j are independent with

θj∣μ,τ,y∼N(yj/σj2+μ/τ21/σj2+1/τ2, 11/σj2+1/τ2).\theta_j \mid \mu, \tau, y \sim N\Big(\frac{y_j/\sigma_j^2 + \mu/\tau^2}{1/\sigma_j^2 + 1/\tau^2},\ \frac{1}{1/\sigma_j^2 + 1/\tau^2}\Big).

Proof. The full conditional of θj\theta_j is proportional to exp⁡(−(yj−θj)2/(2σj2)−(θj−μ)2/(2τ2))\exp\big(-(y_j - \theta_j)^2/(2\sigma_j^2) - (\theta_j - \mu)^2/(2\tau^2)\big), a normal density whose precision is the sum of the two precisions and whose mean is the precision-weighted average. □\square

The posterior mean is μ+(1−Bj)(yj−μ)\mu + (1 - B_j)(y_j - \mu) with the shrinkage factor Bj=σj2/(σj2+τ2)B_j = \sigma_j^2/(\sigma_j^2 + \tau^2), so it lies between μ\mu and yjy_j, and a group with a larger standard error is pulled further toward μ\mu.

2. The center given the spread. Integrating out the θj\theta_j gives yj∣μ,τ∼N(μ,σj2+τ2)y_j \mid \mu, \tau \sim N(\mu, \sigma_j^2 + \tau^2) independently, so with wj=1/(σj2+τ2)w_j = 1/(\sigma_j^2 + \tau^2),

μ∣τ,y∼N(μ^,Vμ),μ^=∑jwjyj∑jwj,Vμ=1∑jwj.\mu \mid \tau, y \sim N(\hat\mu, V_\mu), \qquad \hat\mu = \frac{\sum_j w_j y_j}{\sum_j w_j}, \qquad V_\mu = \frac{1}{\sum_j w_j}.

Proof. The log density in μ\mu is −12∑jwj(yj−μ)2-\tfrac12\sum_j w_j (y_j - \mu)^2, a quadratic with minimum at μ^\hat\mu and curvature ∑jwj\sum_j w_j. □\square

3. The marginal posterior of the spread. With μ^\hat\mu and VμV_\mu as functions of τ\tau,

p(τ∣y)∝p(τ) Vμ1/2∏j=1J(σj2+τ2)−1/2exp⁡(−(yj−μ^)22(σj2+τ2)).p(\tau \mid y) \propto p(\tau)\, V_\mu^{1/2} \prod_{j=1}^J (\sigma_j^2 + \tau^2)^{-1/2} \exp\Big(-\frac{(y_j - \hat\mu)^2}{2(\sigma_j^2 + \tau^2)}\Big).

Proof. p(τ∣y)∝p(τ)∫∏jN(yj;μ,σj2+τ2) dμp(\tau \mid y) \propto p(\tau)\int \prod_j N(y_j; \mu, \sigma_j^2 + \tau^2)\, d\mu. Write ∑jwj(yj−μ)2=∑jwj(yj−μ^)2+(μ−μ^)2/Vμ\sum_j w_j (y_j - \mu)^2 = \sum_j w_j (y_j - \hat\mu)^2 + (\mu - \hat\mu)^2/V_\mu; the Gaussian integral over μ\mu gives 2πVμ\sqrt{2\pi V_\mu}. □\square

So the posterior can be computed by a one-dimensional grid over τ\tau, then draws of μ\mu from result 2 and of θ\theta from result 1, with no Markov chain.

4. Propriety. As τ→∞\tau \to \infty, Vμ1/2∼τ/JV_\mu^{1/2} \sim \tau/\sqrt J, the product is ∼τ−J\sim \tau^{-J}, and the exponential factor goes to 1, so the likelihood factor of result 3 decays like τ1−J\tau^{1 - J}. At τ=0\tau = 0 it is finite and positive. Hence:

  • a uniform prior on τ\tau gives a proper posterior if and only if J≥3J \ge 3;
  • the prior p(τ)∝1/τp(\tau) \propto 1/\tau, or a uniform prior on log⁡τ\log\tau, gives an improper posterior for every data set, because ∫0dτ/τ\int_0 d\tau/\tau diverges at 0.

For the eight schools (J=8J = 8) the log of the likelihood factor has slope −7.00-7.00 in log⁡τ\log\tau between τ=1000\tau = 1000 and 1000010000, as the formula says. Gelman (2006) made this point and recommended a half-Cauchy prior on τ\tau as a default.

5. The eight schools. Rubin (1981) analysed coaching effects on a test in eight schools. The estimates are y=(28,8,−3,7,−1,1,18,12)y = (28, 8, -3, 7, -1, 1, 18, 12) with standard errors σ=(15,10,16,11,9,11,10,18)\sigma = (15, 10, 16, 11, 9, 11, 10, 18). Results 1 and 2 give, for fixed τ\tau:

τ\tau μ^\hat\mu Vμ\sqrt{V_\mu} posterior means of θ1,…,θ8\theta_1, \ldots, \theta_8 given τ\tau
0 7.69 4.07 all 7.7 (complete pooling)
5 7.85 4.49 9.9, 7.9, 6.9, 7.7, 5.8, 6.7, 9.9, 8.1
10 8.13 5.52 14.2, 8.1, 5.0, 7.6, 3.1, 4.9, 13.1, 9.0
25 8.55 9.89 22.9, 8.1, 0.4, 7.3, 0.1, 2.2, 16.7, 10.8
100 8.73 35.65 27.6, 8.0, -2.7, 7.0, -0.9, 1.1, 17.9, 11.9

With a uniform prior on τ\tau (on [0,200][0, 200], which holds all but a negligible part of the mass), result 3 on a grid of step 0.010.01 gives E[τ∣y]=6.57\mathbb{E}[\tau \mid y] = 6.57, posterior median 5.245.24 and 95% quantile 17.1717.17. Averaging over τ\tau gives E[μ∣y]=7.93\mathbb{E}[\mu \mid y] = 7.93 and

E[θ∣y]=(11.40,7.89,6.13,7.64,5.13,6.14,10.67,8.46).\mathbb{E}[\theta \mid y] = (11.40, 7.89, 6.13, 7.64, 5.13, 6.14, 10.67, 8.46).

School A's raw 2828 shrinks to 11.411.4, because its standard error is large and the other schools suggest that effects that large are rare. The maximum of the marginal likelihood is at τ=0\tau = 0, so empirical Bayes would pool completely; the full posterior keeps a real chance that τ\tau is 10 or more.

6. Centred and non-centred forms. In the centred form above, when τ\tau is small the θj\theta_j must all be close to μ\mu, and when τ\tau is large they are free. The posterior of (θ,log⁡τ)(\theta, \log\tau) then has the shape of a funnel, with a narrow neck that Gibbs samplers and Hamiltonian Monte Carlo explore poorly. The non-centred form writes θj=μ+τηj\theta_j = \mu + \tau\eta_j with ηj∼N(0,1)\eta_j \sim N(0, 1) a priori, which removes the prior dependence between η\eta and τ\tau. Papaspiliopoulos, Roberts and Sköld (2007) show that the centred form mixes better when the data are informative about each θj\theta_j (small σj\sigma_j relative to τ\tau), and the non-centred form when they are not, as in the eight schools.

References

  1. Andrew Gelman, John B. Carlin, Hal S. Stern, David B. Dunson, Aki Vehtari and Donald B. Rubin, Bayesian Data Analysis, 3rd edition, CRC Press, 2013, Chapter 5 (hierarchical models, the normal model with exchangeable parameters, the eight schools example and priors for the group-level variance)
  2. D. V. Lindley and A. F. M. Smith, Bayes estimates for the linear model, Journal of the Royal Statistical Society B 34(1), 1972, pages 1 to 41, with discussion (normal priors in stages and exchangeability of the group parameters; general locator)
  3. Rubin 1981, pages 377 to 401 (the eight coaching experiments; general locator)
  4. Andrew Gelman, Prior distributions for variance parameters in hierarchical models, Bayesian Analysis 1(3), 2006, the improper posterior under the prior 1/tau, the problems of the inverse gamma prior with small parameters, and the half-Cauchy prior (general locator)
  5. Papaspiliopoulos, Roberts and Sköld 2007, centred and non-centred parametrizations and their effect on Gibbs samplers (general locator)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/0A2RZM/text.yaml