Adaptive rejection sampling Created 2026-10-05 Updated 2026-10-06
Adaptive rejection sampling builds a piecewise linear upper envelope for a differentiable log-concave probability density, samples from its piecewise exponential form, and accepts with the target-to-envelope ratio. Adding evaluated points improves the envelope without changing the target distribution. Initial tangent slopes must yield integrable tails. The accepted draws are exact samples, unlike a finite run of Markov chain Monte Carlo.
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.
Burn-in 2026-10-20
The initial segment of a Markov chain Monte Carlo run discarded to reduce dependence on its starting state. A fixed discarded count is a choice to assess using Markov chain Monte Carlo convergence diagnostics, not a proof that the retained sample has reached its stationary distribution.
For a positive Harris recurrent Markov chain with invariant probability and , its time average converges almost surely to the invariant expectation:This is the consistency result for Markov chain Monte Carlo averages. Independent-observation variance formulas do not follow from this theorem.
Integrating the two rates out of the Poisson count change-point model with gamma priors gives these weights up to a common factor, by the defining Gamma function integral. Normalizing across the finitely many possible indices gives the exact marginal posterior distribution of , providing a check on Markov chain Monte Carlo estimates. One can also draw from these weights and then draw both rates from their conditional Gamma distributions, producing independent exact joint posterior samples.
MCMC trace diagnosis and proposal tuning Created 2026-10-14 Updated 2026-10-20
A trace of a Markov chain Monte Carlo parameter helps distinguish slow movement, long rejection plateaus, and movement between separated regions. Very small random-walk proposals give high acceptance but slow diffusion; very large proposals produce low acceptance and repeated states. Record acceptance rates alongside trace plots and effective sample size of a Markov chain before deciding which scale to change. Correlated posterior directions often benefit from block proposals with a covariance fitted during a preliminary tuning run. A trace alone cannot prove convergence or identify the unique cause of poor movement; dispersed chains and stationary summaries provide additional evidence. Freeze tuning before the main sampling phase, or use adaptation satisfying an appropriate ergodicity theorem.
Monte Carlo integration 2026-10-14
To calculate , generate independent with density and average . Integrability gives convergence by the strong law of large numbers; finite variance gives an unbiased estimate with variance . Applying this to indicators estimates probabilities. Correlated Markov chain Monte Carlo samples can also approximate the integral, but their error is determined by the chain's dependence rather than the independent-sample variance formula.
Monte Carlo standard error 2026-10-20
The Monte Carlo standard error estimates the standard deviation of a simulation-based estimate across repeated simulation runs. For an average of independent random variables with finite variance , it is . Under a suitable central limit theorem for Markov chain Monte Carlo, correlated draws instead give the approximation , where is the effective sample size of a Markov chain for the particular estimated function . This measures numerical uncertainty in an estimate, not uncertainty in the unknown parameter itself.
A normal local effect can be represented by a standardized latent variable independent of the hyperparameters, with . This preserves the hierarchical model while changing the coordinates explored by Markov chain Monte Carlo. It often improves mixing when individual effects are weakly informed, reducing strong scale-effect dependence. Centered coordinates can be better with very informative individual data. The stochastic prior on implements the transformation correctly; re-expressing an existing density directly instead requires the appropriate Jacobian determinant.
Most high-dimensional phase space has negligible equilibrium probability. Uniform sampling spends nearly all its work in these irrelevant regions and seldom visits the small subset that dominates the partition function or the numerator of an equilibrium average. The resulting estimator can have enormous variance.
Importance sampling places samples where the product of statistical weight and observable matters. Sampling the Boltzmann distribution, for example, converts a weighted phase-space integral into an equilibrium expectation. If a Markov chain Monte Carlo algorithm is used, adequate exploration of separate free-energy basins and allowance for autocorrelation remain necessary.
Direct independent sampling is preferable. The posterior distribution is the standard beta distribution , for which exact posterior moments and standard random-number generators are available. For example, draw independent and with the same rate, and return . This has the required beta distribution and avoids Markov chain Monte Carlo convergence problems. A correct, converged MCMC method could sample this target, but it is unnecessarily complicated here.
Past exam of the mathematics course of the University of Cambridge 2004 iii Paper 40 5 vi Solution Created 2026-10-03 Updated 2026-10-14
Under the reference convention , the hypothesis becomes absence of the free group contrast . Introduce an inclusion indicator : set when , and use its stated proper normal prior when . Assign positive prior probabilities to those models, and retain in both.
A birth draws from a proposal probability density function and appends it as ; the reverse death deletes it. The Jacobian is one. At fixed , the likelihood ratio isThus the birth acceptance ratio before capping iswhere is the normalized prior. Again, taking cancels that factor. Use the reciprocal death rule and ordinary within-model parameter updates.
After warm-up, the Markov chain Monte Carlo occupation fraction estimates the desired probability:This requires the chain to explore both models and satisfy its usual ergodic convergence conditions. Under the original continuous normal prior alone, the equality event has posterior probability zero; the explicit model indicator supplies the necessary prior atom. If intercept selection from part (v) is also performed, use two indicators and count all sampled states with , regardless of the intercept indicator.
Past exam of the mathematics course of the University of Cambridge 2005 iii Paper 47 5 b Solution Created 2026-10-03 Updated 2026-10-14
For each observation time, use only the currently susceptible risk set , with new-infection indicators . PutThis is the spatial Bernoulli infection model, under conditional independence of the indicators. Distances must be positive. Already infected trees should not be included as new susceptible trials. The minus sign in the power kernel is present in the original PDF, although it is absent in the converted TeX.
The parameter must be nonnegative: for and positive exposure, is not a probability. Therefore the stated unrestricted normal prior distribution cannot literally define the model. A coherent interpretation is a normal prior distribution restricted to ,Here is the standard normal distribution function. Use the same proper prior distribution in both kernel models. The given Gaussian prior distributions for and are mathematically valid on the real line for finite positive distances, though restricting them to positive values would impose decaying kernels and would require the corresponding normalized prior distributions.
The full conditional kernels areNeither is generally normal or another elementary conjugate family: the infection factors contain , and depends nonlinearly on . Thus a simple conjugate Gibbs sampler is unavailable. This does not make Gibbs sampling logically impossible; exact rejection or slice conditional draws could be used if implemented. A straightforward alternative is Metropolis–Hastings algorithm updates within each coordinate.
For example, put and use symmetric Gaussian random-walk proposals for . The target in these coordinates isThe factor is the Jacobian determinant and must be retained. Accept according to the ratio of this target, either for a block or one coordinate at a time. Posterior averages and quantiles of and estimate the requested marginal posterior distributions.
To compare kernels, introduce with positive model prior distribution probabilities . Under model two replace by , defining . The joint model/parameter target iswhere or and is its normalized proper prior distribution. Within each model use the preceding random-walk updates. For a concrete model switch, keep , propose the other model's kernel parameter independently from its prior distribution, and use equal forward and reverse switch-selection probabilities. A move from draws and has ratioAccept with the minimum of this ratio and one. The auxiliary-coordinate swap has absolute Jacobian determinant one, so no additional factor occurs; unequal switch-selection probabilities would require their reverse/forward ratio. This is a valid model-switching Markov chain Monte Carlo construction even though the two active models have equal parameter dimension. Prior distribution proposals may be inefficient, so fitted proposals can be substituted provided their probability densities remain in the acceptance ratio.
After checking mixing, estimate posterior model probabilities by the fractions of retained iterations in each model. The Bayes factor in favor of the first kernel isUse the posterior distributions within each model as well as these odds to assess the competing distance kernels. Proper prior distributions and their model-dependent normalizing constants are essential for this comparison.
Past exam of the mathematics course of the University of Cambridge 2007 iii Paper 48 5 b iii Solution Created 2026-10-03 Updated 2026-10-14
The event (m=N) represents no change within the observed sequence: every observation belongs to the first-rate segment, and the second-rate segment is empty. It is not the event ; under continuous independent rate priors that exact equality has posterior probability zero. The endpoint is instead a distinct index value with positive prior mass.
For retained Markov chain Monte Carlo draws , the direct estimate isIts consistency follows from the ergodic theorem for a positive Harris recurrent Markov chain. The draws are correlated, so an independent-binomial standard error would generally be incorrect; uncertainty should account for the Markov chain Monte Carlo asymptotic variance.
A conditional Monte Carlo alternative averages the conditional probability from the preceding solution:The tower property of conditional expectation shows that its posterior expectation is the same target. This replaces an indicator by its conditional expectation; for correlated chains one should assess efficiency rather than automatically assume its entire asymptotic variance is smaller.
An exact finite-sum check is available by integrating out both rates. The marginal posterior weights of a Poisson count change point areThese follow from the Gamma function integral . All omitted prior-normalization and factorial factors are independent of , so they cancel from this ratio. This exact calculation provides a useful independent check on either simulation estimate.
Past exam of the mathematics course of the University of Cambridge 2008 iii Paper 44 4 a Solution Created 2026-10-03 Updated 2026-10-14
The transformation centers day at zero and measures it in standard-deviation units. It reduces numerical scale differences and makes the intercept-like parameter refer to the middle of the observed time range. In nonlinear regression this can reduce posterior parameter dependence and improve Markov chain Monte Carlo mixing. It also makes priors on the growth coefficient easier to interpret; it does not change the curve family.
Past exam of the mathematics course of the University of Cambridge 2008 iii Paper 44 4 h Solution 2026-10-14
Model A has fifteen separate curve parameters plus one error-scale parameter. With such broad priors, one might have expected more of those sixteen parameters to be effectively estimated, rather than , and might also have expected its greater unpooled flexibility to give better fit than the displayed . Model B instead has a smaller mean deviance despite sharing information between trees.
This is a diagnostic concern, not a mathematical impossibility. Effective parameter count in DIC depends on posterior curvature and parameterization, while mean posterior deviance is not minimized deviance. A weakly identified nonlinear asymptote–slope trade-off, skewness, multiple posterior regions or slow Markov chain Monte Carlo mixing could explain the unexpected comparison. For A, the implied deviance at the posterior mean is ; for B it is . Inspect traces, effective sample sizes, independent chains and fitted curves, and extend sampling where needed. Fifty thousand iterations alone do not establish convergence.
Past exam of the mathematics course of the University of Cambridge 2009 iii Paper 36 2 g Solution Created 2026-10-03 Updated 2026-10-14
The WinBUGS model uses a finite truncation of the reciprocal prior. The numbered lines have the following roles:
- Line (1) forms , the normalized prior probability vector on the integer labels . The deterministic sum may be declared after its use because the model is declarative.
- Line (2) assigns that categorical distribution. The following observation model treats the supplied value as observed data, rather than as an unknown parameter.
- Line (3) forms observation probabilities for and zero for . For integer , the small positive offset in
step(N-j+0.01)includes the endpoint without depending on the convention at zero. There are exactly nonzero entries, so this vector sums to one.
Combining that categorical distribution observation likelihood with the truncated reciprocal prior producesThe Markov chain Monte Carlo output approximates this posterior. The actual PDF separates the observation line from the preceding comment; it must remain an active stochastic statement.
Past exam of the mathematics course of the University of Cambridge 2009 iii Paper 36 3 c Solution Created 2026-10-03 Updated 2026-10-14
Centre and scale both predictors, particularly the raw dose whose scale is much larger than that of . For example use , and the linear predictor . This reduces the intercept-slope correlations and numerical scale disparities; further orthogonalizing correlated columns or updating coefficients jointly can improve Markov chain Monte Carlo mixing. The exact old prior can be retained through the corresponding coefficient transformation; assigning new independent priors to transformed coefficients would instead change the prior.
For weakly informed plate effects or small , use the non-centred Gaussian random-effect parameterisation with . This often reduces dependence between the scale and local effects; it is not guaranteed to outperform the centred version when plate effects are strongly informed. Sensibly calibrated proper priors also avoid the enormous initial log intensities permitted by the stated coefficient ranges. Use dispersed chains and Markov chain Monte Carlo convergence diagnostics to assess stationarity, agreement between chains and effective sample size of a Markov chain. Reparameterization can improve mixing; simply retaining more iterations does not remove poor mixing.
Past exam of the mathematics course of the University of Cambridge 2010 iii Paper 33 5 Solution Created 2026-10-03 Updated 2026-10-20
The Metropolis–Hastings algorithm proposes and moves from the current state with acceptance probabilityOn rejection it retains . The target need only be known up to its normalizing constant, but it must define a proper probability distribution. The accepted off-diagonal probability flow iswhich is symmetric in and proves detailed balance. This permits considerable flexibility in proposals, including joint moves when a posterior distribution has strongly correlated parameters, but requires proposal tuning and can waste computation on rejections.
A Gibbs sampler instead updates a coordinate or block from its exact full conditional distribution, holding the other coordinates fixed. This is a special Metropolis–Hastings algorithm update with acceptance probability one: the joint density factors into the unchanged marginal density and the proposed conditional density, which cancel in the acceptance ratio. The coordinate update preserves the target; composing such updates therefore preserves it too, although an entire deterministic sweep need not itself be reversible.
Use Gibbs sampling when the conditional laws are easy to simulate and suitably chosen blocks mix well. Scalar updates can mix poorly under strong posterior distribution correlation, whereas a blocked Gibbs sampler can alleviate that dependence. Prefer a flexible Metropolis proposal when conditional draws are difficult or a well-tuned joint proposal is more effective. Variations include random or systematic coordinate scans, random-walk Metropolis algorithms, independence proposals, and using Metropolis updates for difficult blocks inside a Gibbs scheme. Both methods generate dependent draws; usable long-run estimates require an appropriate irreducible, aperiodic chain and assessment of mixing, not merely a formal update rule.
For the change-point calculation, put andMultiplication of the Gaussian likelihood function by the specified prior distribution gives the formal posterior distribution kernel, with respect to and counting measure on ,
There is an empty component under an improper prior at . The sum is independent of , whose prior distribution is flat on all of . For every fixed finite and , the kernel is a strictly positive constant in , henceThe configuration has positive prior probability . Integrating over, for example, a bounded interval of and already makes the joint normalization infinite. Thus the printed prior distribution does not produce a posterior probability distribution. This failure is present for every data set, not just for a special arrangement of observations.
The formal full conditionals expose exactly where the requested sampler breaks. For , completing the two mean squares givesThe variance kernel is that of when , and the discrete conditional probabilities are proportional to . At the conditional kernel for is constant and cannot be normalized; it is not a normal distribution with an infinite variance. Therefore no valid Gibbs sampler, and no value of , exists for the model as printed. A chain that simply substitutes an arbitrary distribution for this missing conditional would be sampling a different model.
Here is a fully specified proper-prior repair retaining the no-change configuration. Choose fixed hyperparametersindependently, with . Its Gaussian change-point posterior with proper priors isIt is normalizable even for degenerate data: the likelihood function is at most , and its integral against the variance prior distribution is bounded byThe normal mean priors integrate to one, and the normalizing constant is positive. This proves posterior propriety for the repaired model.
Completing the conditional squares gives the Gaussian change-point Gibbs updates. DefineThe four updates areAt , , giving its proper prior distribution unchanged. Starting from any finite means, positive variance and allowed , cycle through these four updates using the latest values. The sum-of-squares terms can be evaluated from cumulative data sums; normalize the discrete log weights after subtracting their maximum to avoid numerical underflow. The proper positive conditionals allow movement among all split values and throughout the continuous parameter support.
Under this specified repair, is the posterior probability of no change within the observed sequence: all data points belong to the first mean regime. For retained draws after initialization has ceased to affect the estimates, its Markov chain Monte Carlo estimator isAlternatively average the displayed conditional probability of at the sampled continuous parameters, giving an estimate by Rao-Blackwellization. Autocorrelation must be accounted for in its Monte Carlo uncertainty. These are probabilities and estimators for the explicitly repaired model; the original unnormalizable kernel supplies neither.
Past exam of the mathematics course of the University of Cambridge 2010 iii Paper 36 2 d Solution Created 2026-10-03 Updated 2026-10-14
Under independent area counts and independent area prior distributions, the joint posterior distribution factors into the gamma posteriors. For each simulation , draw one joint vector by independently generatingRank the risks within that joint draw, taking rank one to mean highest risk:The empirical posterior rank distribution and highest-risk probability areIndependent gamma draws make this direct Monte Carlo integration, so Markov chain Monte Carlo is unnecessary here. Continuous posteriors give ties probability zero, and the highest-risk probabilities sum to one. The same ranking calculation can be applied to dependent joint draws from a richer hierarchical Bayesian model; ranking separate posterior means would discard the uncertainty that the program is intended to measure.