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 , 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, of the 50 should be seniors. Check that the strata add up: 20 + 30 = 50.
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
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.
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.
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: , so . See Capture and Recapture.
Now you
Suppose the tagged fish spread right through the pond before the next catch. Is the estimate sound?
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 , 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 cm and you measure n = 36 people. The standard error is 12 ÷ 6 = 2 cm, since , 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 , the error is 12 ÷ 12 = 1 cm, half of 2.
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
Its mean is the population mean , and its variance is : n independent variances add to , and dividing the total by n divides the variance by . The square root, , is the standard error. See Mean and Variance of X-bar and Standard Error.
With and n = 100, the standard error is . 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.
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.
Now you
Sigma is 12 and n is 4. What is the standard error?
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 , since , 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.
a percent is a hundredth, so n% of a quantity is that quantity × n/100
Make a quarter
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.
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.
Now you
The sample mean is 56 and the standard error is 1. What is the 95 percent interval?
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 , usually that nothing has changed, find how likely a result at least this extreme would be if were true, and reject 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 . A result that would be rare under 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 true. Check the count: 9 heads happen in 10 ways and 10 heads in 1, so 10 + 1 = 11.
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, , claims no effect. The alternative, , 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.
The z-test handles a mean when is known: . 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.
For a proportion from a small sample, use the binomial directly: if a die is fair, sixes in 60 rolls follow , 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
The claimed mean is 67, sigma is 10, n = 4, and the sample mean is 77. What is z?
The claimed mean is 84, sigma is 20, n = 25, and the sample mean is 80. What is z?
Which test fits which question?
| Question | Test |
|---|---|
| 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.
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 , 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.
Spread can be tested too. Scale a sample variance by 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
There is one sample of 8, one claimed mean, and the population spread is unknown. Which test applies?
|t| = 1.14 against a critical value of 2.2. What do you conclude?
The mistakes worth naming
- Reading a p-value backwards. It is the probability of the data given the null hypothesis, never the probability of the null hypothesis.
- Choosing the tail after seeing the data. That doubles the true false-alarm rate.
- Treating "not significant" as "no effect". A small sample often gives too little evidence to reject anything.
- Dividing by n for a sample variance. Divide by n − 1.
- Dropping the continuity correction. A count of 40 covers 39.5 to 40.5.
- Believing a big sample fixes a biased one. Size reduces random error and does nothing to systematic error.
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.