BUGS Created 2026-10-06 Updated 2026-10-14
BUGS specifies a probabilistic model through stochastic nodes, deterministic nodes and observed data, then uses Markov chain Monte Carlo to simulate its Bayesian posterior. Its normal sampling notation uses a precision parameter rather than a variance, and its gamma notation uses shape and rate.
Normal-gamma distribution 2026-10-14
A normal-gamma conjugate prior for the mean and precision parameter of a Gaussian distribution specifies a Gamma distribution in the shape-rate convention and a conditional Gaussian distribution . Its joint probability density function is proportional to , with . For independent observations with Gaussian distribution , multiplication by the likelihood and completing the square givesand . The identity behind conjugacy is .
Past exam of the mathematics course of the University of Cambridge 2008 ib Paper 1 7H Solution Created 2026-09-24 Updated 2026-10-14
Let and . The Gaussian distribution likelihood is proportional to . Multiplying by the normal-gamma distribution prior gives the quadratic exponent . Completing the square,The power of is , so the posterior distribution has exactly the required family withandFor a proper prior, and . The separate factor is retained in both densities; it does not add to the update of . This is a conjugate prior for the Gaussian mean and precision parameter.
Past exam of the mathematics course of the University of Cambridge 2008 iii Paper 44 3 g Solution 2026-10-14
The hierarchical Bayesian model separates variability between individuals from variability between repeated measurements on an individual. In WinBUGS,
dnorm takes a precision parameter, so inverse variance is the appropriate second argument.Line (1) gives , hence a positive log-normal distribution for each within-individual variance. Estimating the shared parameters supplies partial pooling of these variances without forcing them equal. Line (2) assigns a proper bounded flat prior to the between-individual standard deviation , and line (3) does the same for the standard deviation on the log-variance scale. The broad bounded priors on and are also proper.
This is a reasonable structure for heterogeneous repeated measurements, but flat does not mean uninformative on all transformed scales. The bounds must be wide enough for plausible values, while such enormous ranges can put substantial mass on implausible predictions. Use prior predictive checks and sensitivity analysis, and check the Markov chain Monte Carlo convergence diagnostics. Serial dependence or systematic trends would require an extension of the independent-measurement likelihood.
Past exam of the mathematics course of the University of Cambridge 2010 iii Paper 36 4 c Solution Created 2026-10-03 Updated 2026-10-14
The bounded uniform prior distributions on the slopes and population intercept are proper and broad on their stated scale. They allow either sign but are not invariant to changes of units. The residual precision parameter has a proper shape-rate prior. Equivalently, has inverse-gamma distribution with the same shape and scale. This is a commonly used diffuse choice, but it is not literally noninformative and its tail behaviour merits sensitivity analysis.
The prior for is uniform on , so the induced density of isIt is integrable at zero, unlike the usual scale-invariant variance kernel . The latter kernel, often called the standard variance Jeffreys prior, would cause an improper posterior from a log-uniform random-effect scale prior here. After integrating the child intercepts, each child's response vector has a normal likelihood with covariance matrix . For fixed positive , this covariance remains nonsingular at , and the marginal likelihood has a positive finite limit there. On a compact set of the other parameters its positivity givesConsequently the scale-invariant kernel cannot be normalized to a posterior distribution. A proper prior on the standard deviation avoids this problem. This familiar scale prior is not necessarily the actual Jeffreys prior for an additive variance component derived from the observed-data likelihood; the latter can be finite at zero.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 3 b Solution Created 2026-10-03 Updated 2026-10-14
Let , and . These are the two prior precision parameters. Completing the square in gives the normal-normal conjugacy updateThus the posterior mean is a precision-weighted average of the observed mean and the prior center zero. The posterior variance is the reciprocal of the total precision.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 4 f Solution Created 2026-10-03 Updated 2026-10-06
Represent the independent locally flat intercept prior distributions by broad finite uniform priors, for example on ; this is proper and approximately constant over plausible mortality logits. With calibrated above, rough BUGS code isUse and supply treated death counts with totals , and control death counts with totals . In BUGS, the second
model {
mu ~ dnorm(0,0.25)
tau ~ dunif(0,A)
invtau2 <- pow(tau,-2)
for (j in 1:J) {
alpha[j] ~ dunif(-10,10)
beta[j] ~ dnorm(mu,invtau2)
logit(thetaC[j]) <- alpha[j]-beta[j]/2
logit(thetaT[j]) <- alpha[j]+beta[j]/2
rC[j] ~ dbin(thetaC[j],nC[j])
rT[j] ~ dbin(thetaT[j],nT[j])
oddsRatio[j] <- exp(beta[j])
}
}dnorm argument is a precision parameter, so 0.25 corresponds to variance four. Initialize the positive scale away from zero. Monitor and study odds ratios, checking Markov chain Monte Carlo convergence diagnostics and sensitivity to the finite intercept bounds and scale prior distribution. The fitted hierarchy combines binomial sampling uncertainty with between-study heterogeneity. Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 4 h Solution Created 2026-10-03 Updated 2026-10-06
Conditional on , let and independently . The normal distribution with the stated precision parameter can be generated asThereforeby the defining normal distribution and chi-squared distribution representation of Student's t-distribution. Its density isThus is the location and is the scale, not the standard deviation: . Each study gets its own independent chi-squared draw in this Student t random-effect model.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 4 i Solution Created 2026-10-03 Updated 2026-10-06
The Student t random-effect model is useful when most studies are comparable but occasional genuine departures are more frequent than a normal distribution hierarchy allows. Its heavier tails permit a study effect far from without forcing a large common between-study heterogeneity scale on every study. In the Gaussian scale mixture representation, a small study-specific lowers its precision parameter and weakens its shrinkage.
Use this as robust partial pooling when occasional atypical effects are plausible. Known systematic population or design differences should still be modeled explicitly; a heavy tail cannot identify or correct within-study bias by itself.
Past exam of the mathematics course of the University of Cambridge 2023 iii Paper 216 1 e Solution 2026-09-28
Put . The Weighted graph Laplacian of the tree is defined byMultiplication of the Gaussian likelihood by the prior shows that, conditionally on the precision parameter ,Completing the square therefore givesAs a function of , the posterior density isso, in shape-rate notation,The precision matrix has the sparsity pattern of a tree. A sparse Cholesky decomposition and its triangular solves have cost and storage on this graph, while the gamma update also costs . Hence each systematic-scan Gibbs sampler iteration costs .
Let , , and . The independent observations in the normal linear model giveThe centered design condition removes the term:The stated prior density factors into independent normal distributions for the regression intercept and regression coefficient . Multiplication by the likelihood function therefore leaves separate quadratic expressions in the two coefficients. Define the positive posterior variancesand the posterior meansBy completing the square, the joint posterior density isEquivalently,This is Gaussian conjugacy for a normal linear model. Each posterior precision parameter is the sum of its data and prior precision parameters. The formulas remain valid when : all are then zero, so the posterior distribution of equals its prior distribution.
Scalar static-state Kalman update Created 2026-10-03 Updated 2026-10-14
Suppose the predicted state has normal distribution and the new observation is , where the measurement noise is independent of the state and previous observations. Gaussian conditional expectation givesThe coefficient is the scalar Kalman gain. The posterior mean is a weighted mean of the predicted state and the new observation, with the more precise quantity receiving more weight. For , the same equations can be expressed in precision parametersThe two precision parameters add because the measurement noise is independent of the state and past observations. Completing the square in the product of the prior density and the likelihood function gives this form directly. This is a Gaussian conditional expectation for a fixed unknown state; a moving state additionally requires a Kalman prediction step.