Simulated Nulls

A hypothesis test asks how data would look in a world without the effect you are looking for. These pages build null worlds by simulation for three tests (a difference in means, a trend and a shift at an unknown year) and compare each result with the test's formula.

What a Test Does

A statistical test asks whether data could plausibly have come from a world without the effect you are looking for. It takes three choices:

  • Test statistic: the quantity of interest, computed from the data, through which the effect is hopefully detectable if it is there.
  • Null model: how data would arise in a null world without the effect, along with whatever else that world assumes.
  • Alternative hypothesis: which values of the statistic count as evidence against the null, such as large values only, or values far from the null in either direction.

Then the test:

  1. Estimate the sampling distribution of the test statistic under the null model: with a formula when one is available, or by simulating many datasets from the null world and computing the statistic for each.
  2. Compare the statistic from the observed data to this distribution.
  3. The p-value is how often the null world produces a statistic at least as extreme as the observed one.

A small p-value says the data would be unusual in that null world. It does not say:

  • how likely the null is to be true;
  • whether the test would detect an effect that is there.

Simulation is what makes this approach general. Formulas exist only for some pairs of statistic and null model, and usually need extra assumptions, such as Gaussian data. Simulation can be used with any statistic you can compute and any null model you can draw data from, so you can choose the statistic that matches the question and the null that matches how the data arise. Searching a series for the year its level shifted is an example: the standard formulas for that search (Andrews 1993; Hansen 1997) are large-sample approximations that depend on how the search is set up, and simulation gives the p-value for the search you ran.

Three Ways to Build a Null World

The pages build their null worlds in three ways:

  • Shuffle the group labels, or the order of the data: a permutation test. It needs the data to be exchangeable when the null holds, as when a treatment was assigned at random, or when any year of a record could trade places with any other.
  • Resample the data with replacement in a way that makes the null true, such as pooling the two groups or assigning the values to years at random: a nonparametric bootstrap test.
  • Simulate from a model fitted with the null imposed, such as a Gaussian with no trend: a parametric bootstrap test.

The bootstrap is more often used for confidence intervals, and the two uses are easy to confuse. A bootstrap confidence interval resamples the data as they are, so its simulated statistics are centered on the observed value. A bootstrap test resamples from a world in which the null holds, so its simulated statistics are centered on the value the null implies, such as a difference of zero. The two-groups page shows both on one axis.

The Examples

Each page asks one question of one dataset:

  1. Two groupsDo mosquitoes prefer beer drinkers?Difference in means: shuffled labels, Welch's \(t\)-test and a bootstrap interval
  2. TrendIs the surge rising?Least-squares slope: Gaussian, shuffled and resampled years, and the \(t\)-test
  3. BreakpointDid the level shift?Largest \(|t|\) over every split: a search is many tests at once

About These Pages

Simulations
Everything runs in your browser. Each page's code is tested against the same analysis run separately in Julia.
Sources
The steps of a test follow Allen Downey's "There is still only one test", and the pages are modeled on Andrew Heiss's nullworlds.andrewheiss.com. Andrews (1993) and Hansen (1997) are cited in full on the breakpoint page.
Course
Made for BEE 4850/5850, Environmental Data Analysis and Simulation, Cornell University.