Sampling and Inference

☰ Contents

Inference uses a sample to make a claim about a whole population. Every method below answers one question: how far can a sample be trusted to speak for the population it came from?

What is a sample, and what makes a good one?

A population is the whole group you want to know about, and a sample is the part you actually measure. A number describing the population, such as its mean, is a parameter; the same number computed from the sample is a statistic, and it estimates the parameter. See Populations and Samples. A good sample is chosen at random, so every member has a known chance of selection and the method favors no group. To survey 50 of a school's 1,000 students, let a random number generator pick 50 of them, a sampling fraction of 1/20, since 1,000 ÷ 50 = 20. Randomness removes bias: volunteers, or people easy to reach, differ from the rest in ways a larger sample cannot fix. When the population has groups of known size, a stratified sample takes from each in proportion: if 400 students are seniors, 400 × 1/20 = 20 of the 50 should be seniors. Check that the strata add up: 20 + 30 = 50.

tagged 60, netted 40, tagged in the net 16k/n = 16/40 ≈ m/N ⇒ N ≈ mn/k = 60 × 40 / 16 = 150m = 60n = 40

16 of the 40 netted are tagged, so the pond is estimated at mn/k = 150: the tagged share of the net stands in for the tagged share of the pond, and the pond really holds 200, 50 away

Tag 40 and net 50, then read the estimate

Usample30970
There are a thousand people in the population, and you can only ask thirty. Full lesson: Populations and Samples

In a simple random sample every member has the same probability. In a systematic sample you take every tenth name on a list, which relies on the order of the list being fair. See Sampling Methods.

ABC
In a stratified sample, split the population into groups, then take from each group in proportion to its size. Full lesson: Sampling Methods

In an experiment the researcher assigns the treatment, for example by a coin toss. In an observational study people put themselves into groups, and those groups can differ before the treatment starts. Only random assignment supports a claim about cause. See Observational Studies and Experiments.

drugdummyhealthier firstfrailer firstchance splits every other difference evenly
Assigning at random spreads every other difference evenly over the two groups. Full lesson: Observational Studies and Experiments

Capture and recapture estimates a population that cannot be listed. Tag 60 fish and release them. Later catch 80 fish and find 12 tagged. If the tagged fish have mixed fully, the same fraction of the lake is tagged: 60/N = 12/80, so N = 60 × 80 / 12 = 400. See Capture and Recapture.

Now you

taggeduntaggedfish

Suppose the tagged fish spread right through the pond before the next catch. Is the estimate sound?

taggeduntaggedfish

Suppose half the tags fall off before the next catch. Is the estimate sound?

Why is the mean of a sample so well behaved?

Averaging makes the sample mean well behaved, because it cancels much of the chance variation in single values. Every sample of the same size gives a different mean, so the sample mean has its own distribution, the sampling distribution. See The Sampling Distribution. Its center is the population mean μ, and its spread is the standard error σ/√n, which shrinks as the sample grows. For large n its shape is close to normal, whatever the population looks like: that is the central limit theorem. Suppose heights have σ = 12 cm and you measure n = 36 people. The standard error is 12 ÷ 6 = 2 cm, since √36 = 6, so most sample means land within about 4 cm of μ. The square root slows the gain: halving the standard error takes 4 times as many readings. Check with 144 people: since √144 = 12, the error is 12 ÷ 12 = 1 cm, half of 2.

0.511.522.5μ = 1n = 16σ/√n = 0.25

the means of a skewed population pile into a symmetric bell, and their spread is σ/√n — quadrupling n halves it; here σ/√n = 0.25

Take n to 100 and read the spread

2345678population mean 5
Keep only the means and they pile up between 4 and 6, where the scores ran 2 to 8. Full lesson: The Sampling Distribution

Its mean is the population mean μ, and its variance is σ²/n: n independent variances add to nσ², and dividing the total by n divides the variance by n². The square root, σ/√n, is the standard error. See Mean and Variance of X-bar and Standard Error.

With σ = 20 and n = 100, the standard error is 20 ÷ √100 = 2. Individual values scatter by about 20, and their average by about 2.

The central limit theorem needs n to be large enough: about thirty is usually enough, and a badly lopsided population needs more. See The Central Limit Theorem and Applying the Theorem.

Take means of samples from it and they pile up symmetrically anyway. Full lesson: The Central Limit Theorem

The same approximation works for the binomial when np and n(1 − p) are both greater than 5: a normal curve with mean np and variance np(1 − p) sits on top of the bars. The bars have width, so a count of 40 covers 39.5 to 40.5. See Approximating a Binomial and Continuity Correction.

678
A binomial bar for X = 7 really covers everything from 6.5 to 7.5. Full lesson: Continuity Correction

Now you

what does this come to?

Sigma is 12 and n is 4. What is the standard error?

what does this come to?

Sigma is 6 and n is 25. What is the standard error?

How do you estimate a population value from a sample?

A population value is estimated by a single number, a point estimate, or by a range, a confidence interval. The sample mean x̄ is the point estimate of the population mean μ, and it is unbiased: over many samples its average is exactly μ. See Point Estimates. A 95% confidence interval adds and subtracts about two standard errors. If 100 bags have a mean mass of 502 g and σ is 10 g, the standard error is 10 / 10 = 1 g, since √100 = 10, so the interval runs from about 500 g to 504 g. It works because about 95 in 100 sample means land within two standard errors of μ, so about 95 in 100 such intervals contain μ. When σ is unknown, estimate it from the sample, dividing by n − 1 rather than n, because data sit closer to their own mean than to μ. Check the width: 504 − 500 = 4, which is four standard errors.

24060%

a percent is a hundredth, so n% of a quantity is that quantity × n/100

Make a quarter

xy
Any one estimate still misses. A point estimate says nothing about by how much. Full lesson: Point Estimates

See Unbiased Sample Variance.

A confidence interval reports a range instead. Take the estimate, then add and subtract 1.96 standard errors, because z = 1.96 leaves 2.5 percent in each tail of the normal distribution.

xy
So report the estimate ± 1.96 standard errors — the z that leaves 2.5 percent in each tail. Full lesson: Confidence Intervals

The 95 percent describes the method: repeat it many times and 95 in 100 of the intervals contain the true mean. The one in front of you either contains it or does not. See Confidence Intervals.

xy
The 95 percent describes the method: 95 in 100 such intervals contain the true mean. Full lesson: Confidence Intervals

Now you

xy

The sample mean is 56 and the standard error is 1. What is the 95 percent interval?

xy

The sample mean is 78 and the standard error is 5. What is the 95 percent interval?

How does a hypothesis test work?

A hypothesis test asks whether data are too surprising to blame on chance. Assume the null hypothesis H₀, usually that nothing has changed, find how likely a result at least this extreme would be if H₀ were true, and reject H₀ if that probability, the p-value, is below a significance level chosen in advance, often 5%. Suppose a coin tossed 10 times gives 9 heads. If the coin is fair, the chance of 9 or more heads is 11 in 1,024, about 1%, so a one-tailed test at 5% rejects H₀. A result that would be rare under H₀ counts as evidence against it. A two-tailed test, chosen in advance, also counts 1 or fewer heads, so the p-value becomes 22 in 1,024, since 11 + 11 = 22, about 2%, which still rejects. Failing to reject never proves H₀ true. Check the count: 9 heads happen in 10 ways and 10 heads in 1, so 10 + 1 = 11.

−3−2−101231.96z = 1.5p = 0.1336p ≥ 0.05: do not reject H₀two-tailedone-tailed

z = 1.5: p = 0.1336 ≥ 0.05, so a result this far out is not surprising enough under H₀, and H₀ is not rejected; the bar is 1.96

Two-tailed: find the smallest z that rejects H₀ at 5%

The null hypothesis, H₀, claims no effect. The alternative, H₁, claims an effect and needs evidence before you believe it. See Null and Alternative Hypotheses.

Decide before seeing the data which tail counts. A one-tailed test puts the whole 5 percent in one tail. A two-tailed test splits it, 2.5 percent in each tail, so its critical value sits further out. See One-Tailed and Two-Tailed.

xy
Testing for any change splits it: 2.5 percent in each of the two tails. Full lesson: One-Tailed and Two-Tailed

The z-test handles a mean when σ is known: z = (x̄ − μ) / (σ ÷ √n). Subtract the claimed mean, divide by the standard error, and compare z with the critical value. See The Z-Test.

A critical region fixes the boundary in advance: mark off the most extreme 5 percent, and any result landing there rejects the null. A p-value shades everything at least as extreme as the result you saw and reports that area as a probability. See Critical Regions and P-Values.

xy
Mark off the most extreme 5 percent. That shaded tail is the critical region. Full lesson: Critical Regions
xy
Shade everything at least as extreme as what you actually saw. Full lesson: P-Values
A p-value of 0.03 means results this extreme would happen about three times in a hundred if the null were true. It does not mean there is a 97 percent chance the effect is real, and it says nothing about how large the effect is.

For a proportion from a small sample, use the binomial directly: if a die is fair, sixes in 60 rolls follow B(60, 1/6), and the probability of 17 or more sixes is the p-value. See Testing a Proportion with the Binomial.

A type one error rejects a null hypothesis that was true, and its probability is the significance level you chose. A type two error fails to reject a false one. Demand more evidence and the first rate falls while the second rises. See Type One and Type Two Errors.

Now you

xy

The claimed mean is 67, sigma is 10, n = 4, and the sample mean is 77. What is z?

xy

The claimed mean is 84, sigma is 20, n = 25, and the sample mean is 80. What is z?

Which test fits which question?

QuestionTest
Is this mean different, σ known?Z-test
Is this mean different, σ estimated?One-sample t-test
Do two groups differ in mean?Two-sample t-test
Are two categorical variables related?Chi-squared for independence
Do counts match a claimed distribution?Chi-squared goodness of fit
Is the variability different?Chi-squared for a variance, or the F-test

The chi-squared tests compare observed counts with expected counts. In a two-way table, the expected count for a cell is the row total times the column total divided by the grand total. Square each gap between observed and expected, divide by the expected count, and add up every cell. The degrees of freedom are (rows − 1) × (columns − 1). See Expected Frequencies and The Chi-Squared Test for Independence.

cityfarmtotalcats241640dogs61420total303060
Two in three owners keep cats. If home makes no difference, every column splits the same way. Full lesson: Expected Frequencies
x3.84
Read the total against the chi-squared curve for 1 degree of freedom. Full lesson: The Chi-Squared Test for Independence

The goodness of fit test uses the same statistic against a claimed distribution: a fair die rolled 60 times expects ten of each face. See The Chi-Squared Goodness of Fit Test.

When σ must be estimated from the sample, use t instead of z. The one-sample t-test divides the gap between the sample mean and the claimed mean by s ÷ √n, with n − 1 degrees of freedom. The two-sample t-test divides the gap between two sample means by the standard error of that gap. See The One-Sample T-Test and The Two-Sample T-Test.

xy
With the spread estimated rather than known, the curve keeps heavier tails. Full lesson: The One-Sample T-Test

Spread can be tested too. Scale a sample variance by (n − 1) / σ² and it follows a chi-squared curve with n − 1 degrees of freedom. To compare two variances, divide the larger by the smaller; that ratio is F. See Testing a Variance with Chi-Squared and Comparing Two Variances with the F-Test.

Now you

xy

There is one sample of 8, one claimed mean, and the population spread is unknown. Which test applies?

xy2.2

|t| = 1.14 against a critical value of 2.2. What do you conclude?

The mistakes worth naming

Where this leads next

The binomial and normal distributions are built in the sets, counting and distributions guide. The mean and variance being tested come from the averages and spread guide. The test for a correlation coefficient is in the correlation and regression guide.

Related guides: Probability and Combined Events.

Your turn

Three to try — tap what you get.

Taking every 10th name from a list is a

All else equal, a larger sample makes an estimate

A sample that overrepresents one group is

Questions and answers

What is a p-value actually telling you?
A p-value is the probability of a result at least as extreme as the one observed, assuming the null hypothesis is true. It is a statement about the data given the hypothesis, not about the hypothesis given the data. A p-value of 0.03 means results this unusual would occur about three times in a hundred if nothing were going on; it does not mean a 97% chance that the effect is real, and it says nothing about its size.
What does a 95 percent confidence interval mean?
It means the method produces an interval containing the true population value about 95 times in every 100 samples. The confidence belongs to the procedure, not to the particular interval in front of you, which either contains the true value or does not. In practice it is read as a plausible range for the population parameter, and its width is as informative as its center: a wide interval is an admission that the sample was too small.
Why does the central limit theorem matter so much?
Because it makes inference possible without knowing the shape of the population. However the underlying data is distributed, the mean of a large enough sample is approximately normally distributed around the population mean, with a spread that shrinks as the sample grows. That single fact lets one set of normal-distribution tools be applied to samples from populations that are skewed, lumpy or entirely unknown.
What is the difference between standard deviation and standard error?
Standard deviation describes how spread out the individual values are. Standard error describes how spread out the sample means would be across repeated samples, and it equals the standard deviation divided by the square root of the sample size. Individuals do not become less variable as you collect more data, but their average becomes more reliable, which is why the standard error shrinks and the standard deviation does not.
What is a type one error?
A type one error is rejecting a null hypothesis that was true, a false alarm. Its probability is the significance level you chose, so testing at 5 percent accepts a one in twenty chance of it. A type two error is failing to reject a null hypothesis that was false, a missed detection. Lowering the significance level reduces type one errors and increases type two errors, so the choice is a trade-off decided by which mistake is more costly.
When do you use a t-test instead of a z-test?
Use a z-test when the population standard deviation is known, or the sample is large enough that estimating it makes little difference. Use a t-test when the standard deviation is estimated from a small sample, because that estimate carries its own uncertainty. The t-distribution has heavier tails than the normal to account for it, so it demands a slightly larger result before declaring significance, and it converges to the normal as the sample grows.
Mr. Chalk