Sampling & Distributions

BASC0005 Quantitative Methods 2: Data Science and Visualisation

Ollie Ballinger

Selection Bias

  • We rarely have all the data on a specific population; Often, we only have a sample.
  • When a sample is drawn randomly, we can use the distribution of the sample to make inferences about the population.
  • Selection Bias can occur when our sample is not randomly selected.
  • Wald was interested in the population of bomber planes, but only observed a highly biased sample: those that returned.
    • This is known as survivorship bias, and is a subset of general selection bias

Populations and Samples

  • There are two kinds of distributions: populations and samples.
  • A population is the set of all relevant measurements
  • A sample is a group of observations drawn in some way from a wider population
Population Sample
All the fish in the sea The fish I caught
The adult population of the UK Census responses
All U.S. Navy Bomber planes Bombers that made it back to base
All 19-20 year olds in the world The people in this classroom
A person’s movements over a month Mobile phone location pings
Public sentiment on race in South Africa Tweets about race from South African users

Outline

  1. Basic Statistics
  2. The Central Limit Theorem
  3. Quantifying Uncertainty

Basic Statistics

Measures of Spread: Variance

  • The sample variance, s², measures how far, on average, the values are from the mean
  • (xᵢ − x̄) is how far each value xᵢ is from the mean x̄. Squaring makes s² sensitive to extreme values (outliers)
  • s² is not in the same units as the xᵢ: it is in squared units
  • What does a variance of 1,008 mean? Or 0.0001?

The Central Limit Theorem

Inferring from samples

  • There are generally equal numbers of men and women in the population*;
  • In other words, a random individual plucked from this population has a ~50% chance of being a man or a woman.
  • Let’s assume a variable where woman=1, man=0
  • If I take a random sample of 4 people,
    • we might expect 2 men and 2 women, or a [0,0,1,1] sample
    • But we might not be entirely surprised if we got all men [0,0,0,0] or all women [1,1,1,1].
    • Similarly, you could flip a coin 4 times and get all heads or all tails.

Central Limit Theorem

  • This is the most important concept you will learn in this course.
  • If you take sufficiently large random samples from the population,

The distribution of sample means will be approximately normally distributed

  • Regardless of the underlying population distribution

Why does this matter?

  • This means that we can use the normal probability model to quantify uncertainty when making inferences about a population mean based on the sample mean.
  • In other words, because we know the shape of the normal distribution, we can precisely estimate the likelihood of observing a sample mean as extreme as the one we have
  • We rarely observe the whole population, but if we have a large enough random sample, we can assume that the mean of this sample has a:
    • 68% chance of falling within 1 standard deviation of the population mean
    • 95% chance of falling within 2 standard deviations of the population mean
    • 99.7% chance of falling within 3 standard deviations of the population mean

Estimating Union membership in America

Estimating Union membership in America

  • What if we took a random sample of 1000 people.
    • How likely is it that not a single person in the sample is a member of a union?
    • Given such a large sample, it’s unlikely that our sample mean would be 0 due to pure chance.
  • But how unlikely?

Estimating Union membership in America

The distribution of sample means becomes normal, regardless of the underlying distribution

The distribution of sample means becomes normal, regardless of the underlying distribution

The distribution of sample means becomes normal, regardless of the underlying distribution

The distribution of sample means becomes normal, regardless of the underlying distribution

Why the CLT is ✨magic✨

  • In these examples, I’ve had access to the entire population and have been drawing thousands of large samples to show that their means are normally distributed.
  • If you have one sufficiently large random sample, you can ASSUME that the distribution of sample means will be normally distributed.
    • You can ASSUME that the mean of your sample has a 95% chance of falling within 2 standard deviations of the population mean

Quantifying Uncertainty

The Signal and the Noise

  • Signal
    • meaningful information that you’re actually trying to detect.
  • Noise
    • random, unwanted variation or fluctuation that interferes with the signal.
  • Sometimes we may observe a strong signal
    • E.g. a big difference between two values (e.g. income for men vs women)
    • But there may be big differences between all the values; in other words, there may be lots of noise. The observed difference could be due to chance.
    • If there’s a big difference in our two values, but the rest of the values are close together, the likelihood that our observed difference is due to chance is low.

Recap

  1. A population is the set of all relevant measurements
  2. A sample is a group of observations drawn in some way from a wider population
  3. If you take sufficiently large random samples from the population,
    1. The distribution of sample means will be approximately normally distributed
  4. If you have one sufficiently large random sample, you can ASSUME that the distribution of sample means will be normally distributed.
    1. You can ASSUME that the mean of your sample has a 95% chance of falling within 2 standard deviations of the population mean

Bayesian thinking

  • Frequentist: probability is how often something happens over many repeats
  • Bayesian: probability is how strongly you believe something
    • Prior: what you believe before you see the data
    • Posterior: what you believe after you see the data
  • Today: one Bayesian idea that you can use every day

Mammogram example (next slides). Both bars use the same count scale.

Who was Thomas Bayes?

  • Thomas Bayes (c. 1701–1761) was a Presbyterian minister and a mathematician
  • He was a minister in Tunbridge Wells and a Fellow of the Royal Society
  • He never published his rule. After his death, his friend Richard Price found it in his papers and published it in 1763
  • He is buried in Bunhill Fields, a few minutes’ walk south of Old Street station
    • William Blake and Daniel Defoe are buried there too
  • Go and visit him: the base rate of famous statisticians in EC1 is low

The Bayes family vault, Bunhill Fields, London. Photo: Cory Doctorow (2007), CC BY-SA 2.0, via Wikimedia Commons.

A small % of a big number beats a big % of a small number

  • South Wales Police used live facial recognition at the 2017 Champions League final in Cardiff
  • The system compared faces in the crowd with a watch list
  • 93% of its alerts named the wrong person
  • Why? A small error rate × a very big crowd is more than a high hit rate × a few wanted people
  • Always ask: how big is each group?

Source: South Wales Police figures, reported by The Guardian, 5 May 2018.

The mammogram problem

  • 1% of women in a screening group have breast cancer
  • The test detects 90% of cancers
  • The test also flags 9% of healthy women
  • A woman tests positive. What is the chance that she has cancer?
    • Answer: 9 of 98 positives, about 9%
    • Only 21% of 160 gynaecologists chose the right answer
  • Tip: count people, not percentages

Numbers from Gigerenzer et al. (2007), Psychological Science in the Public Interest 8(2).

The same pattern, in many places

  • Drunk driving is much more dangerous per mile, but most road deaths involve no drunk driver
  • 8 of 9 women with breast cancer have no affected mother, sister or daughter
  • My damage detector in Kharkiv: it flagged 32% of damaged buildings but only 0.9% of intact ones. Most flags were still intact buildings
  • Also: COVID deaths in vaccinated people, DNA database matches, heart attacks at ‘normal’ cholesterol
  • Geoffrey Rose: many people at a small risk can give more cases than a few people at a high risk

Chart: Ballinger (2025), Remote Sensing of Environment, Tables 1–2. Other sources: NHTSA (2022 data); Collaborative Group (2001), Lancet 358.

My research: same detector, very different precision

  • The Pixel-Wise T-Test (PWTT) flags damaged buildings in free radar imagery
  • We tested it on 904,977 buildings in 30 cities, with UN damage labels
  • Kremenchuk: the best AUC of all 30 cities (0.93), but only 3% of flags were real damage
    • Only 0.11% of its buildings were damaged
  • Gaza: a lower AUC (0.78), but 74% of flags were real damage
    • 72% of its buildings were damaged
  • The detector did not change. The base rate changed.

Source: Ballinger (2025), Remote Sensing of Environment, Tables 1–2. Statistics are weighted by building area.

Bayes’ rule

  • How to read it, step by step:
      1. Start with the prior: 1% of women have cancer
      1. Multiply by the likelihood: 90% of them test positive. These are the true alarms
      1. Divide by the evidence: all positive tests, true alarms + false alarms
      1. The result is the posterior: 9%
  • Trap: P(+ | cancer) = 90% is not P(cancer | +) = 9%
  • The false alarms come from the big group, so they decide the answer

The base rate decides

  • The same test (90% sensitivity, 9% false alarms) at different base rates
  • Rare condition: almost every alarm is false
  • Common condition: most alarms are true
  • So a result means different things in different populations
  • Link to today: a base rate is a population quantity, and we estimate it from a sample

P(condition | positive) from Bayes’ rule, with the prior on the x-axis.

Any Questions?

o.ballinger@ucl.ac.uk