Lite / Textbooks / Engineering Research and Experimental Methods / Chapter 7
7. Inference done right
Introduction
Statistics cannot tell you that an idea is true, but it can tell you how surprising your data would be if it were not, and how large the effect plausibly is. This chapter reports standard errors and confidence intervals, interprets p-values correctly alongside effect sizes, counts the hidden tests behind flexible analyses, and uses the bootstrap to get intervals from your own data when formulas run out.
Figure 7.1. Every analysis path is a test (described in words)
Bars of the chance of at least one false positive among m independent tests at α = 0.05: 5 % for m = 1, 14.3 % for m = 3, 26.5 % for m = 6 and 64.2 % for m = 20. Trying many analyses until one works makes a false discovery likely.
Explanation
Built from 4 School lessons. Each part is the lesson's own explanation.
7.1 Standard errors and confidence intervals
'The new method is 0.3 s faster.' Plus or minus what? Without that, the sentence means almost nothing.
SD versus SE
The standard deviation s describes how much single runs vary. The standard error s/√n describes how much the mean would vary if you repeated the whole experiment. Error bars must say which they show; SE bars are √n times shorter.
What 95% confidence means
If you repeated the experiment many times and built an interval each time, about 95% of those intervals would contain the true value. It does not mean there is a 95% probability the true value is in this particular interval, although for practical decisions the interval is your best summary of plausible values.
Small samples
With fewer than about 30 runs per group, replace 1.96 by the t critical value (for 10 degrees of freedom it is 2.23). Intervals get wider, honestly reflecting less information.
Derivation: Standard error of a difference
Let X̄₁ and X̄₂ be means of independent samples, sizes n₁ and n₂, SDs σ₁ and σ₂.
Var(X̄ᵢ) = σᵢ²/nᵢ, because averaging n independent runs divides the variance by n.
For independent random variables, Var(X̄₁ − X̄₂) = Var(X̄₁) + Var(X̄₂): the minus sign does not cancel variance.
So SE_diff = √(σ₁²/n₁ + σ₂²/n₂), estimated with sample SDs s₁, s₂.
Approximate 95% CI: (x̄₁ − x̄₂) ± 1.96 · SE_diff for large samples; use the t critical value with Welch degrees of freedom for small ones.
Paired designs (same seed for both methods) use the SD of the per-seed differences instead, which is often much smaller.
Common mix-ups
The SE of a difference is the sum of the two SEs.
✓ For independent estimates you add variances, so SE_diff = √(SE₁² + SE₂²), which is smaller than SE₁ + SE₂.
Open the Lite lesson: Standard errors and confidence intervals
7.2 p-values and effect sizes, done correctly
p = 0.03. Does that mean a 3% chance your result is a fluke? (No. But almost everyone thinks so.)
The definition
The p-value is the probability, assuming the null hypothesis and the model are true, of obtaining a test statistic at least as extreme as the one observed. Small p means the data would be surprising under the null. That is all.
Three misreadings
- p is not the probability that the null is true. 2. p > 0.05 does not show there is no effect (it may be low power). 3. p does not measure importance: with enough runs, trivial effects reach tiny p. Report the estimate, its interval and an effect size alongside p.
t and d
The t statistic = difference / SE_diff: how many standard errors the difference is from zero. It grows with √n. Cohen's d = difference / pooled SD: the difference in units of run-to-run spread. It does not grow with n, so it is the better measure of size.
Common mix-ups
A smaller p-value means a bigger or more important effect.
✓ p mixes effect size with sample size. Report the effect size and interval to say how big the effect is.
Open the Lite lesson: p-values and effect sizes, done correctly
7.3 Module check: forking paths and multiple comparisons
Nothing in this simulation has any real effect. Yet with a few innocent choices, a third of studies 'find' one. How?
The garden of forking paths
Which outcome, which outlier rule, which subgroup, when to stop: each choice is a fork. If choices are made after looking at data, the analysis effectively tries many paths and reports one. The nominal 5% then hugely understates the real false-positive rate, even with no intent to deceive.
p-hacking and HARKing
p-hacking: trying analyses until p < 0.05. HARKing: Hypothesising After the Results are Known, presenting a post-hoc pattern as if predicted. Both are questionable research practices that manufacture findings. Remedies: pre-registration, one primary analysis, corrections for planned multiple tests, and labelling the rest exploratory.
Expected false discoveries
Run m null tests at α and expect m·α false positives. If only a fraction of ideas are true, the share of significant results that are false can be large: with 90 null and 10 real ideas, α = 0.05 and power 0.8, there are 4.5 false versus 8 true hits, so 36% of 'discoveries' are false.
Derivation: Bonferroni from the union bound
Let Eᵢ be the event 'test i is a false positive', with P(Eᵢ) = α* for each of m null tests.
Family-wise error rate FWER = P(E₁ ∪ … ∪ E_m).
Union bound: P(∪Eᵢ) ≤ Σ P(Eᵢ) = m·α*, whatever the dependence between tests.
Choose α* = α/m. Then FWER ≤ m · α/m = α.
For independent tests the exact rate is 1 − (1 − α/m)^m, slightly below α.
Cost: each test is stricter, so power falls. For many tests, false-discovery-rate methods trade a few false positives for more power.
Common mix-ups
p-hacking requires deliberately cheating.
✓ It usually happens through many reasonable-looking choices made after seeing the data; good intentions do not prevent it, pre-registration does.
Open the Lite lesson: Module check: forking paths and multiple comparisons
7.4 The bootstrap: uncertainty from your own data
Your metric is a median of skewed settling times. There is no neat formula for its standard error. Can the data tell you instead?
Resample, recompute, repeat
Treat your sample as a stand-in for the population. Draw n values from it with replacement, compute the statistic, and repeat a thousand times. The histogram of results shows how uncertain the statistic is. For a mean it agrees closely with s/√n; for medians and ratios it gives answers formulas cannot.
Comparing two methods
For a difference, resample each group separately (or resample paired seeds together), compute the difference each time, and take the 2.5% and 97.5% quantiles. Record the bootstrap seed: bootstrap intervals are random too, and should be reproducible.
Where it fails
The bootstrap assumes runs are independent and the sample represents the population. With very small n (under about 10), heavy tails or dependent runs (time series), the interval can be too narrow. It never corrects a biased sample or a confounded design.
Derivation: The bootstrap idea
We want the sampling distribution of a statistic θ̂ (e.g. the median): how it would vary over new datasets of size n.
We cannot draw new datasets from the true population F.
Plug-in principle: replace F by the empirical distribution F̂ that puts mass 1/n on each observed value.
Drawing n values from F̂ = resampling the data with replacement. Compute θ̂* on each resample.
Repeat B times (B ≈ 1000–10,000). The spread of the θ̂* estimates the spread of θ̂: SE_boot = SD(θ̂*).
Percentile interval: the 2.5% and 97.5% quantiles of θ̂*. Assumes the sample represents the population; it cannot fix bias or a tiny n.
Common mix-ups
The bootstrap creates extra data, so small samples become reliable.
✓ It only reuses the data you have; it estimates uncertainty, it cannot reduce it or fix a biased sample.
Open the Lite lesson: The bootstrap: uncertainty from your own data
Worked examples
Standard errors and confidence intervals: example 1
Baseline 2.40 s (s 0.30, n 25); new 2.15 s (s 0.35, n 25). 95% CI of the improvement?
Solution
SE = √(0.09/25 + 0.1225/25) = √0.0085 = 0.0922 s. Improvement 0.25 s ± 1.96 × 0.0922 = ± 0.181 → [0.069, 0.431] s.
p-values and effect sizes, done correctly: example 1
n = 50 each, d = 0.1. What is t, roughly, and is the effect important?
Solution
t ≈ 0.1 × √25 = 0.5, not significant. With n = 5000 each, t ≈ 0.1 × 50 = 5, p < 0.001, but d is still 0.1: a tiny effect relative to spread. Importance depends on the requirement, not on p.
Module check: forking paths and multiple comparisons: example 1
You pre-register 4 metrics as co-primary. What threshold per test keeps FWER at 0.05?
Solution
Bonferroni: 0.05 / 4 = 0.0125. A metric with p = 0.02 is not significant under this plan, and you report it as such.
The bootstrap: uncertainty from your own data: example 1
1000 bootstrap medians, sorted: the 25th is 2.18 s and the 975th is 2.52 s. Interval?
Solution
Percentile 95% CI ≈ [2.18, 2.52] s (the 2.5% and 97.5% quantiles of 1000 values sit near positions 25 and 975).
Interactive figures, in words
Figure 7.2 from Standard errors and confidence intervals
In the top panel, keep the difference at 0.3 and shrink the SE: watch the interval tighten. In the lower panel, set the true difference to 0.2 and run several sets of 20 replications. Count how many intervals miss the truth each time.
The top panel draws an estimate as a dot with a horizontal 95% interval, a dashed zero line and a green line for the smallest effect of interest. The lower panel draws 20 replicated intervals around a true value; intervals that miss it are shown dashed in red, and the readout counts them.
Figure 7.3 from Module check: forking paths and multiple comparisons
Start with every switch off: the false-positive rate is near 5%. Turn on one fork at a time and note the rate. Turn them all on. Then switch on the Bonferroni correction. Which single fork inflated the rate most?
The forking-paths simulator runs 400 seeded studies in which there is no real effect. Switches add analysis choices (three outcomes, outlier removal, subgroups, peeking). A bar shows the share of studies reporting a 'significant' finding against a marked 5% line. With all switches on it is far above 5%; a Bonferroni switch brings it back near 5%.
Figure 7.4 from The bootstrap: uncertainty from your own data
Do one resample and read the ×counts. Then +1000. Compare the bootstrap SE of the mean with the formula s/√n. Switch to the median: what does the histogram look like now? Reset with a new seed: how stable is the interval?
The bootstrap resampler shows the original values, how many times each was drawn in the latest resample, and a histogram of resampled means or medians with the observed value and the 95% percentile interval marked. Buttons add 1, 100 or 1000 resamples.
Laboratory
These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.
- Equation Lab: Compare (Equation Lab exploration)
Compare two simulated samples and read the difference, its interval, the effect size and the p-value side by side.
Open on the full site - Code Lab (Studio)
Bootstrap a 95 % interval for a median from simulated timings, recording the seed, and compare it with a normal-theory interval.
Open on the full site
Practice
Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.
- Which interpretation of a 95% CI is correct?
Answer it in “Standard errors and confidence intervals” - Error bars labelled 'SD' on 100 runs. Compared with SE bars they are…
Answer it in “Standard errors and confidence intervals” - Paired design: per-seed differences have SD 0.12 s over 16 seeds. SE of the mean difference?
Answer it in “Standard errors and confidence intervals” - Which statement about p = 0.01 is correct?
Answer it in “p-values and effect sizes, done correctly” - p = 0.4 in a study of 6 runs per group. What can you conclude?
Answer it in “p-values and effect sizes, done correctly” - Checking the p-value after every 5 runs and stopping when p < 0.05 is a problem because…
Answer it in “Module check: forking paths and multiple comparisons” - Which is the best remedy for forking paths?
Answer it in “Module check: forking paths and multiple comparisons” - When is a bootstrap interval least trustworthy?
Answer it in “The bootstrap: uncertainty from your own data”
Engineering applications
Many sensors, many tests
Checking twenty sensor channels for a change at α = 0.05 will usually flag one by chance. Controlling the false discovery rate keeps the alarm list honest.
Skewed timing data
Response times have long tails, so a mean and a normal interval mislead. A bootstrap interval for the median reflects the data's real shape.
Watch (optional)
Streaming video uses a lot of data. Everything you need is in the text.
- “p-values: What they are and how to interpret them” by StatQuest with Josh Starmer
- “P-Hacking: Crash Course Statistics #30” by CrashCourse
- “False Discovery Rates, FDR, clearly explained” by StatQuest with Josh Starmer
- “Bootstrapping Main Ideas!!!” by StatQuest with Josh Starmer
Summary
- Report the estimate, its interval and an effect size; a p-value alone says little.
- p is the probability of data at least this extreme if the null were true, not the probability the null is true.
- Flexible analyses, peeking and selective reporting multiply the chance of false positives.
- Correct for multiple comparisons or pre-register a single primary analysis.
- The bootstrap resamples your data with replacement to estimate uncertainty; record its seed.
Glossary
- Standard error of the mean
- The standard error of the mean estimates how much a sample mean would vary between repeated experiments: the sample standard deviation divided by the square root of the number of readings. Field Guide
- Repeated trials
- Repeating a measurement or test several times shows how much results vary and lets you average out random error. Field Guide
- Outliers and honest data
- An outlier is a reading far from the rest. It may be a genuine effect or a fault; either way it must be investigated and reported, and any exclusion rule decided before seeing the results. Field Guide
Project: Analyse a simulated study three ways
For a two-condition comparison run in a School simulation, report the difference with a normal-theory interval, a bootstrap interval and a p-value with an effect size. Then show how many results would look significant if you had tested every outcome you recorded.
Deliverables
- Three analyses of the same simulated data
- A multiple-comparison count and correction
- A plain-language statement of what can be concluded
Write it up on paper or in your own notes. Lite never stores what you write.
References
- Ronald L. Wasserstein and Nicole A. Lazar (2016). "The ASA's Statement on p-Values: Context, Process, and Purpose". The American Statistician 70(2), 129–133.
- Joseph P. Simmons et al. (2011). "False-Positive Psychology: Undisclosed Flexibility in Data Collection and Analysis Allows Presenting Anything as Significant". Psychological Science 22(11), 1359–1366.
- Yoav Benjamini and Yosef Hochberg (1995). "Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing". Journal of the Royal Statistical Society, Series B 57(1), 289–300.
- Bradley Efron and Robert J. Tibshirani (1993). An Introduction to the Bootstrap. Chapman & Hall.