University College London · FACULTY OF STATISTICS

PHAS0083 Chap.3 Monte Carlo Simulation and Density Estimates

- one subject, every graph, every model, every mark
7 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 3 of 9 · PHAS0083

Monte Carlo Simulation and Density Estimates

Monte Carlo Simulation and Density Estimates brings computation in early so that later theory can be checked against draws.

It explains that a computer produces pseudo-random numbers whose starting seed determines every later value, and that samplers for other distributions are built from uniforms either by the probability integral transform, which needs the inverse cdf, or by accept-reject sampling under an envelope, whose efficiency is the ratio of the two areas. A Q-Q plot checks a sampler against theoretical quantiles.

Models built from a chain of conditional steps are simulated down that chain of conditional distributions, drawing any latent variable before the variables that depend on it. The empirical cdf then turns draws into probabilities and quantiles; it is unbiased, has a binomial variance, and its relative precision improves only as the inverse square root of the number of draws, which fixes how many draws a target precision needs.

Histograms and kernel density estimates recover the shape of a pdf but depend on a bin width or bandwidth, so the notes use them for plotting and templates while computing every probability from the empirical cdf.

In this chapter

What this chapter covers

  • 01

    Pseudo-random numbers and seeds

  • 02

    Probability integral transform

  • 03

    Accept-reject sampling and efficiency

  • 04

    Simulating hierarchical models

  • 05

    The empirical cdf and quantiles

  • 06

    Number of draws for a target precision

  • 07

    Histograms and kernel density estimates

Worked example · free

Sample a power-law tail by inverting its cdf

Q [4 marks]. A pdf is f(x) = 3/x⁴ for x at least 1. Derive the inverse-cdf sampler and give the draw produced by the uniform value u = 0.875. The marks shown are AskSia practice weighting, not a published UCL marking scheme.
Uniform heights on the vertical axis are carried across to the cdf and down to x, so draws pile up where the cdf is steep, which is where the pdf is large.Uniform heights on the vertical axis are carried across to the cdf and down to x, so draws pile up where the cdf is steep, which is where the pdf is large.0246800.51xu = F(x)cdf of an exponential, scale 2u on the vertical axismaps to x = -2 ln(1 - u)
Uniform heights on the vertical axis are carried across to the cdf and down to x, so draws pile up where the cdf is steep, which is where the pdf is large.
  • 1Integrate: F(x) = 1 - x⁻³ for x at least 1, which rises from 0 at x = 1 towards 1. This allocation is practice weighting, not a UCL marking scheme.
  • 2Invert: u = 1 - x⁻³ gives x = 1/∛(1 - u).
  • 1Substitute u = 0.875: x = (0.125)^(-1/3) = 2.
The sampler is x = (1 - u)^(-1/3), and u = 0.875 maps to x = 2. Every uniform draw gives one accepted value, which an accept-reject scheme could not achieve on this unbounded support. The practice marks are not an official UCL allocation.
Sia tip — Check an inverse-cdf formula at u = 0 and as u approaches 1; the results must be the lower end of the support and the upper end.
Glossary

Key terms

Envelope function
A function lying above the target pdf everywhere, used to propose candidates in accept-reject sampling.
Latent variable
A random variable in a model that is never recorded, such as a true energy before detector smearing.
Empirical cdf
The step function giving the fraction of draws at or below each value.
Kernel density estimate
A smooth pdf estimate formed by averaging a kernel of chosen width centred on every draw.
FAQ

Monte Carlo Simulation and Density Estimates FAQ

What makes a model hierarchical?

A model qualifies as hierarchical when it is built from conditional steps and at least one variable is latent, meaning it is part of the model but never recorded. A detector that records only smeared energies of photons with randomly shifted true energies is an example. If every variable in the chain is recorded, the chain alone does not make it hierarchical.

Why are computer random numbers called pseudo-random?

They come from a deterministic formula that maps one internal state to the next. Good generators leave no pattern that statistical checks can find and have very long periods, but the same seed always reproduces the same sequence, which is useful for checking results.

How many Monte Carlo draws do I need?

For a probability near p known to relative precision delta, the number of draws must be at least (1 - p) divided by p times delta squared. Small probabilities and tight precision are expensive: a tenfold gain in precision costs a hundredfold increase in draws.

Why not compute probabilities from a histogram?

A histogram depends on the chosen bin width and its counts are noisy, so different choices give different answers. The empirical cdf needs no choice and has a known variance, which is why the notes take probabilities, quantiles and thresholds from it.

Study strategy

Exam move

Practise the two sampling methods on paper first: invert three cdfs by hand, including one on an unbounded support, and compute the acceptance fraction of a box envelope for two pdfs with different peak heights. Then run a short script that draws from each sampler, plots a Q-Q plot and compares the empirical cdf with the true cdf, changing only the number of draws so you see the inverse-square-root shrinkage yourself.

For hierarchical models, write each conditional step as a line of the simulation in chain order and state which variables are latent. Learn the precision formula by deriving it from the binomial variance of a count, then apply it to a central probability and to a tail probability to feel the difference in cost.

Finish by comparing a histogram and a kernel estimate for two bin widths and two bandwidths, and write one sentence on why neither should be used to read a quantile.

Working through Monte Carlo Simulation and Density Estimates in PHAS0083? Sia is AskSia’s AI Statistics tutor — ask any PHAS0083 Monte Carlo Simulation and Density Estimates question and get a clear, step-by-step explanation grounded in how PHAS0083 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 32 of your subjects at University College London, plus 1,000+ more Bibles across the AskSia library.
Sia - your PHAS0083 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works