BUGS 2026-10-06
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.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 1 f Solution Created 2026-10-03 Updated 2026-10-06
There is a notation problem here. The posterior predictive probability calculated above is already a fixed number conditional on . Literally,No simulation is needed for that interpretation. The known exposure is also necessary, despite its omission from this part's list of inputs.
The natural uncertain quantity is instead . For its posterior probability of being below one half, draw the rate from its gamma distribution Bayesian posterior and average an indicator. Rough BUGS code isThe monitored average of
model {
lambda ~ dgamma(a+n, b+T)
q <- exp(-lambda)
belowHalf <- step(lambda-log(2))
}belowHalf estimates , equivalently . The equality boundary has zero probability. This code samples the already updated Bayesian posterior; adding the count likelihood function again would count the data twice. Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 1 h Solution Created 2026-10-03 Updated 2026-10-06
A uniform prior on makes the posterior density proportional to the Poisson change-point posterior likelihood above. The zeros trick introduces an observed zero with Poisson distribution mean , making its likelihood function equal to . Choose ; since , this mean is strictly positive. Rough BUGS code, with For , omit the array and set
zero=0 supplied as data, ismodel {
theta ~ dunif(0,T)
for (i in 1:n) {
before[i] <- step(theta-time[i])
}
j <- sum(before[])
logL <- theta-2*T+(n-j)*log(2)
zero ~ dpois(K-logL)
}j <- 0. Monitor the sampled theta to obtain its posterior mean, credible interval and interval probabilities.There is also an exact sampling method. On the posterior density is proportional to , so choose the interval with weightsThen draw from a uniform distribution on and set . These weighted interval draws sample the posterior directly, without asking a local Markov chain Monte Carlo update to cross its discontinuities.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 2 d Solution Created 2026-10-03 Updated 2026-10-06
In Markov chain Monte Carlo, retain the derived quantity at every iteration. Rough BUGS code using the actual observations isSupply
model {
pM ~ dbeta(0.5,0.5)
pT ~ dbeta(0.5,0.5)
milkAnswers ~ dbin(pM,4)
teaAnswers ~ dbin(pT,4)
delta <- pM-pT
positive <- step(delta)
}milkAnswers=3 and teaAnswers=1. Summarize delta by its posterior mean, empirical quantiles and credible interval; the average of positive estimates . Here . Check Markov chain Monte Carlo convergence diagnostics before interpreting the simulation. Since both Bayesian posteriors are independent known Beta distributions, direct independent sampling is an equally valid, simpler way to obtain the same summaries. 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.