Computational statistics 2026-11-05
Computational statistics develops and studies computational procedures for statistical inference. It includes numerical evaluation of likelihood functions, simulation from probability distributions and assessment of uncertainty when an exact symbolic calculation is unavailable. The statistical question and the numerical approximation both need error control.
For example, if independent simulations follow a model and has finite variance, the Monte Carlo estimator estimates , with variance . Halving its standard deviation therefore requires four times as many independent simulations. An optimization routine finding a maximum of a likelihood function and a simulation routine estimating an integral solve different computational tasks, even when both are steps in the same analysis.
Control variates 2026-10-14
A control variate is a random variable with known expected value whose centered value is subtracted from a Monte Carlo estimator to reduce its variance. For a mean-zero vector , put and . When is invertible, the optimal estimator averages and has variance for independent draws. Improvement is strict exactly when .
Past exam of the mathematics course of the University of Cambridge 2001 iii Paper 23 4 c Solution Created 2026-10-03 Updated 2026-10-14
Let have finite variance and mean . An independent-sample Monte Carlo estimator has variance , so its root-mean-square random error is . Three techniques reduce the variance coefficient rather than changing this ordinary rate.
For antithetic variates, couple with and average the pair. With independent pairs, the variance is , compared with for independent function evaluations. If is monotone in a scalar uniform, the covariance is nonpositive: for independent uniforms ,Opposite fluctuations therefore cancel. The reduction factor at equal evaluation count is , where is the paired correlation coefficient; it can approach zero, but positive covariance would make the method worse. This is appropriate for monotone or otherwise negatively coupled payoffs, with cheap complementary paths.
For control variates, use a jointly simulated with known mean and average . It remains an unbiased estimator for fixed , andCompleting the square gives and minimal variance . For contingent claim simulation, an analytically priced related financial payoff, such as a simpler option or discounted terminal stock, can be a useful control. It works best when correlation has large absolute value and simulation of the control adds little cost. A coefficient fixed from an independent pilot keeps the elementary unbiasedness argument valid; estimating it from the same sample can introduce finite-sample bias.
For stratified sampling, partition the sampling space into strata of probabilities , and independently simulate samples conditional on each stratum. The estimator is unbiased and has varianceWith proportional allocation , ignoring integer rounding, this equals . The law of total variance shows the reduction from ordinary sampling is : fixed representation removes randomness in the stratum counts. At equal per-draw cost, minimizing the displayed variance gives and minimum for positive within-stratum variances. This follows by Cauchy-Schwarz inequality and is useful when a low-dimensional coordinate strongly predicts the financial payoff and conditional simulation is easy.
There is no universal ranking. At comparable cost the variance factors depend respectively on paired covariance, squared control correlation, and within-stratum variation. A nearly perfect control can outperform a weak antithetic pair; an appropriate stratification can be almost exact for a nearly stratum-constant financial payoff. Extra construction and sampling costs must be included in a fair accuracy comparison, and the methods can be combined.
Past exam of the mathematics course of the University of Cambridge 2004 iii Paper 35 4 c Solution Created 2026-10-03 Updated 2026-10-14
Let denote the strike, , and suppose , , and . Under the Black-Scholes model and the risk-neutral measure, is normal withApplying risk-neutral valuation to the European call option payoff givesUse , whose differential is precisely the normal density times . The threshold is , soEquivalently, rescale the tail interval to obtain on .
For independent uniform inputs, the Monte Carlo estimator is . It is unbiased, converges by the strong law of large numbers, and has variance . The payoff has finite second moment because the lognormal stock has finite moments. Its estimated standard error is the sample standard deviation divided by .
Past exam of the mathematics course of the University of Cambridge 2015 iii Paper 37 6 i d Solution Created 2026-10-03 Updated 2026-10-06
Apply the Monte Carlo estimator to the observable :The theoretical justification is the ergodic theorem for a positive Harris recurrent Markov chain, not an independent-sample law of large numbers. The Markov chain has finite state space, is irreducible, and has the strictly positive posterior distribution as invariant law, so it is positive recurrent and Harris recurrent with counting measure. The observable is bounded: . Thus the estimator converges almost surely to the posterior expected value from any initial configuration.
Each state also has positive self-transition probability, so the chain is an aperiodic Markov chain. Finiteness then gives geometric convergence and the relevant central limit theorem; serial dependence determines the Markov chain Monte Carlo asymptotic variance if error bars are required. A fixed finite burn-in can be discarded without changing consistency, but independence of the retained states should not be assumed.
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 208 5 a Solution Created 2026-10-03 Updated 2026-10-06
Let be iid with density , set , and put and . The finite-second-moment assumption gives, for ,The sample variance consistently estimates . The central limit theorem and Slutsky theorem therefore give the asymptotic confidence intervalIts confidence probability is approximately , conventionally written ; the printed omits the factor . For , almost surely and the estimator has zero error. This interval concerns iid Monte Carlo estimators; correlated simulation output requires a long-run variance of a stationary process estimate instead of the iid sample variance.
Past exam of the mathematics course of the University of Cambridge 2018 iii Paper 216 6 a Solution Created 2026-10-03 Updated 2026-10-05
Let . To distinguish the number of posterior draws from the training-sample size, write it as ; in the question's sample notation . The Monte Carlo estimator of the requested posterior mean isFor independent exact posterior draws it is unbiased, andThe features are conditioned on as fixed data. The estimated probability concerns a future genuine banknote under the posterior predictive probability, not an indicator sampled from that predictive distribution.
Past exam of the mathematics course of the University of Cambridge 2018 iii Paper 216 6 b Solution Created 2026-10-03 Updated 2026-10-05
Put and . The probit regression likelihood is , so with the stated normal prior,Differentiating gives the probit posterior scoreEquivalently, the th likelihood term is . The prior's gradient is essential.
This posterior density is smooth, positive everywhere, and bounded above by a constant times the Gaussian prior, since the likelihood is at most one and has positive normalizing constant. Its derivatives are integrable: differentiating a likelihood factor gives a bounded normal density, and differentiating the prior gives a linear factor times a Gaussian. Integration by parts therefore yieldsThus each component has a known zero expected value and can be used as a posterior score control variate. This identity differentiates the posterior density in the random parameter; it is distinct from the usual mean-zero score identity for a likelihood under repeated sampling.
The requisite second moments are finite. For , is bounded. For ,Hence the score grows at most exponentially in , and the Gaussian upper bound on the posterior gives finite second moments. For a fixed vector , averaging is therefore an unbiased Monte Carlo estimator of the same mean; suitable coefficients can reduce its variance.
Past exam of the mathematics course of the University of Cambridge 2019 iii Paper 219 2 b Solution 2026-10-03
Treat the simulated pairs as samples from the prior . The numerator and denominator of the posterior mean are then ordinary Monte Carlo estimators, sowhere the normalized importance sampling weights areThe common Gaussian normalizing constant cancels.
Apply Chebyshev's inequality to the Monte Carlo estimator:Thus suffices, givingThis is a finite-sample probability guarantee for every target satisfying the given variance assumption. It is a sufficient sample count supplied by the inequality, rather than a claim that every such target actually needs a million draws.
Generate independent and identically distributed random variables with probability density function , evaluate for each draw, and return the Monte Carlo estimatorLinearity of expectation makes this an unbiased estimator: . Independence and the specified variance give . Its Monte Carlo standard error is therefore , and the strong law of large numbers gives convergence to almost surely.
Stop rejection sampling when exactly target draws have been accepted. The total proposal count is a sum of independent waiting times with geometric distribution, equivalently a negative binomial distribution counting trials. ConsequentlyThe accepted-sample Monte Carlo estimator then has the approximate precision from (a)(iii). The displayed proposal cost is an expected value, which need not be an integer. Spending this many proposals in advance does not ensure that target draws will have been accepted.
Integrating the envelope shows . One trial of rejection sampling draws and an independent from the uniform distribution on , and accepts if . Repeat with fresh independent random variables after each rejection. Ratios need only be evaluated where ; the envelope makes the target zero wherever .
For any measurable set , integration of the conditional probability of acceptance givesTaking the whole domain gives acceptance probability , and dividing gives . Fresh trials therefore supply independent and identically distributed random variables with target probability density function . The corresponding Monte Carlo estimator isThe proposal count up to and including one acceptance has the geometric distributionFor example, the tail-sum formula gives . Thus the expected cost is proposal draws per accepted target draw.
Choose distinct coordinates uniformly for the starting ones; each element of then has starting probability . At each iteration choose one current one and one current zero uniformly and swap them. This implements the normalized proposal distribution from (c)(i), remains in , and needs just one precomputed matrix inverse.
mymcmc <- function(x, k, sigma) {
n <- length(x)
stopifnot(length(k) == 1L, is.finite(k), k == floor(k),
k > 0L, k < n, is.matrix(sigma),
all(dim(sigma) == c(n, n)))
sigma_inv <- invsigma(sigma)
u <- integer(n)
u[sample.int(n, k, replace = FALSE)] <- 1L
draws <- matrix(0, 100L, n)
for (iteration in seq_len(100L)) {
ones <- which(u == 1L)
zeros <- which(u == 0L)
i <- ones[sample.int(length(ones), 1L)]
j <- zeros[sample.int(length(zeros), 1L)]
v <- u
v[i] <- 0L
v[j] <- 1L
alpha <- mylogapp(x, u, v, sigma_inv)
if (runif(1L) < alpha) u <- v
draws[iteration, ] <- u
}
colMeans(draws)
}Sampling positions with
sample.int and then indexing into ones or zeros also works when or . In R, a call such as sample(ones, 1) would incorrectly sample from 1:ones when ones is a single numeric value greater than one.The code records the state after each of exactly transitions, including repetitions after rejection. Its answer is the vector Monte Carlo estimatorThis estimates the posterior mean coordinate by coordinate; because each coordinate is binary, its entries estimate the posterior probabilities of inclusion. Every stored state has coordinate sum , so the estimated means lie in and sum to .
For neighbouring states, the symmetry of the proposal and the Metropolis–Hastings acceptance probability give detailed balance:Thus the posterior distribution is a stationary distribution. Any two states in can be connected by moving the ones that occupy the wrong positions, and the multivariate normal distribution gives strictly positive target masses. The resulting Markov chain is therefore an irreducible Markov chain, and its long-run state averages estimate the posterior mean.
The requested iterations are a finite approximation, without a convergence guarantee or discarded burn-in. A randomly chosen starting subset has the prior distribution, rather than generally the posterior distribution. No aperiodicity assumption is needed for the finite-state Markov chain ergodic theorem for averages; indeed a uniform two-state target with gives a period-two alternating chain. This does not invalidate either the code or the state-average estimator.
Past exam of the systems biology course of the University of Cambridge 2024 Paper 3 2 f Solution 2026-10-20
TODO: Complete the data-specific numerical results and diagnostics when the original
Iris_data.csv is available.Estimate the posterior mean by averaging the retained states:The exact truncated normal distribution reference isFor a posterior well separated from zero, the truncation correction is tiny and the posterior mean is approximately , slightly below the sample mean.
The R continuation prints the Monte Carlo estimator, its approximate batch-based Monte Carlo standard error, and the exact value for comparison:
posterior_mean_mc <- mean(post)
posterior_mean_exact <- m + s * exp(dnorm(m/s, log = TRUE) -
pnorm(m/s, log.p = TRUE))
# Nonoverlapping batches account approximately for serial dependence.
batch_length <- floor(sqrt(length(post)))
number_batches <- floor(length(post)/batch_length)
used <- post[seq_len(batch_length * number_batches)]
batch_averages <- colMeans(matrix(used, nrow = batch_length))
mcse <- sd(batch_averages)/sqrt(number_batches)
cat("Posterior mean, MCMC =", posterior_mean_mc,
" approximate MCSE =", mcse, "\n")
cat("Posterior mean, exact =", posterior_mean_exact, "\n")The batch length must be long enough relative to the chain's dependence for this uncertainty estimate to be reliable. No numerical data-specific posterior mean is determined by the supplied paper alone.
No: Monte Carlo integration is poorly suited to this smooth one-dimensional problem at such a tight tolerance. A sample-average Monte Carlo estimator has a standard error proportional to , whereas the deterministic composite Simpson's rule bound decreases as here and already certifies the target with tens of strips. Random sampling would require vastly more function evaluations and supplies a probabilistic error statement rather than the displayed deterministic guarantee.
Posterior score control variate Created 2026-10-05 Updated 2026-10-14
If a smooth posterior density has vanishing boundary terms, its log-posterior gradient satisfies andThis is a posterior integration-by-parts identity; it concerns differentiation in the random parameter, distinct from the usual mean-zero score identity for sampling distributions. It makes a vector control variate. Finite moments and known coefficients preserve unbiasedness of the Monte Carlo estimator.