๐Ÿ“– Contents · Hub · Full version Chapter 12 ยท Two-Sample Tests
Statistics Easy Read · Chapter 12

Two-Sample Tests

Almost every interesting question in statistics is a comparison. Does this treatment beat that one? Do these two groups of customers behave differently? Did the change we made actually change anything? A one sample test asks whether a single group differs from a fixed number. A two-sample test asks whether two groups differ from each other, and that is the question the world most often cares about. This chapter builds the four workhorse methods: two independent means, paired means, two proportions and the confidence intervals that go with them. It shows you just how to decide which one a study calls for. And it works the math all the way through, so you can see there is no magic in it.

By the end of this chapter you can

  • Tell when two samples are independent and when they are paired, and explain why the difference changes the analysis.
  • State the hypotheses, check the conditions and work out the test statistic for a two-sample t-test of independent means.
  • Shrink a matched pairs study to a single sample of differences, and run a paired t-test.
  • Carry out a two-proportion z-test, including the pooled proportion and the success-failure check.
  • Use a decision guide to choose the right test from the study design, and name a sensible other choice when conditions fail.
  • Build and correctly read confidence intervals for a difference of two means or two proportions.
  • Explain how a two sided test and a confidence interval mirror each other, and the one place that breaks down.
  • State just what a p-value and a 95% confidence interval do and do not mean.

Section 1Two independent means

Side-by-side box plots comparing the distribution of a numeric variable across two groups
Reference. Side by side box plots. They are the standard first look at a two group comparison, showing the center, spread and outliers for each group on one scale. Source and license: see the figure credits

Two groups, one question

Say you have measured a numeric outcome on two separate groups of subjects, such as a test score, a reaction time, a blood pressure or a delivery time. The group averages came out different. They always do. Two samples drawn from the very same population will differ by chance alone. The whole job of a two-sample test is to answer one question: is the gap we saw bigger than chance would easily produce?

The samples here are independent, which has an exact meaning. Knowing any value in group 1 tells you nothing about any value in group 2, and no subject appears in both groups. Two treatment arms assigned at random are independent. Men and women in one survey are independent. The same forty people measured in January and again in June are not, and that is Section 2's problem.

Write the population means as μ1 and μ2. The hypotheses are about the difference:

H0: μ1 − μ2 = 0     Ha: μ1 − μ2 ≠ 0

Notice what the null says: the two populations have the same mean. It does not say the two samples had the same mean. They plainly did not, or you would not be testing anything.

The test statistic, and where it comes from

Every test statistic in this book has the same shape: (what we saw) minus (what the null predicted), divided by how much that amount naturally wobbles. Our estimate of μ1 − μ2 is x̄1 − x̄2. Its wobble is measured by the standard error of the difference. Because the two samples are independent, their variances add, never their standard deviations:

SE = √( s12/n1 + s22/n2 )

and the test statistic is

t = ( x̄1 − x̄2 − 0 ) / SE

Since we estimated both standard deviations from data, the reference curve is a t distribution, not the normal. The degrees of freedom are the awkward part. Use Welch's approximation, which statistical software gives you by default and which you should use by default:

df = ( s12/n1 + s22/n2 )2 ÷ [ (s12/n1)2/(n1−1) + (s22/n2)2/(n2−1) ]

This is rarely a whole number, and that is fine. Working by hand without software, you may round the df down to the nearest whole number. That is cautious on purpose. It gives a slightly wider interval and a slightly larger p-value, so you never overstate your evidence.

ConditionWhat it meansHow to check it
Independence withinObservations inside each group do not influence one anotherRandom sample, or random assignment; sample under 10% of the population
Independence betweenNo subject appears in both groups; no natural pairingRead the study design: this is a design fact, not a data fact
Normality (or size)Each population is roughly normal, or each sample is largeA dot plot or box plot for each group. n ≥ 30 per group makes mild skew harmless.
OutliersNo single point is driving the differenceLook at the box plots; investigate, do not silently delete

A worked example, all the way through

A trainer compares two coaching formats. Format A: n1 = 12, x̄1 = 78.4 and s1 = 8.2. Format B: n2 = 15, x̄2 = 71.9 and s2 = 9.6. People were assigned at random, so the groups are independent. Test at α = 0.05, two sided.

Step 1: the observed difference. 78.4 − 71.9 = 6.5 points.

Step 2: the standard error. First find the two pieces:
s12/n1 = 8.22/12 = 67.24/12 = 5.6033
s22/n2 = 9.62/15 = 92.16/15 = 6.1440
The sum is 11.7473, so SE = √11.7473 = 3.4274.

Step 3: the test statistic. t = 6.5 / 3.4274 = 1.896. The gap we saw is about 1.9 standard errors from zero.

Step 4: degrees of freedom.
Numerator: 11.74732 = 138.00
Denominator: 5.60332/11 + 6.14402/14 = 31.397/11 + 37.749/14 = 2.8543 + 2.6963 = 5.5506
df = 138.00 / 5.5506 = 24.9.

Step 5: the p-value and the decision. With about 25 degrees of freedom, the two sided cutoff at α = 0.05 is t* ≈ 2.06. Our 1.896 does not reach it, and the two sided p-value is about 0.07. Since 0.07 > 0.05, we fail to reject H0.

Step 6: say it in plain English. "Format A came out 6.5 points ahead. But with these sample sizes and this much spread, a gap at least that large, in either direction, would arise about 7 times in 100 even if the two formats were truly the same (t = 1.90, df ≈ 24.9, p ≈ 0.07). The data do not give convincing evidence of a difference." Note what we did not say: we did not say the formats are equal. Failing to reject is a failure to convict, not a verdict of innocence, and the study may simply be too small.

Use Welch's test by default. The older "pooled" two-sample t-test assumes the two populations have equal variances. It combines them into one estimate, which buys slightly more degrees of freedom. But you can rarely know whether that assumption holds. When it is wrong and the sample sizes are unequal, the pooled test's error rate is wrong too. Welch's version costs almost nothing when the variances really are equal, and it protects you when they are not. If your software says "Welch two-sample t-test," you are in good hands.
Interactive Draw real samples from two populations you control, watch the difference between their means bounce around, and see exactly where its standard error comes from: variances add, standard errors do not. Open full ↑
Key points
  • Independent samples means no subject is in both groups and no natural pairing exists.
  • Variances add: SE = √(s12/n1 + s22/n2). Standard deviations never add.
  • t = (x̄1 − x̄2) / SE, compared with a t curve with Welch degrees of freedom.
  • "Fail to reject" means the evidence is too weak. It never proves that the means are equal.

Section 2Paired samples

Chart of repeated measurements taken on the same subjects across conditions
Reference. Repeated measurements on the same subjects. When every subject gives more than one value, the observations are linked, not independent, and the analysis must respect that. Source and license: see the figure credits

What makes a pair a pair

Sometimes the two columns of numbers are not two separate crowds of people. They are the same people twice, or two people matched to each other on purpose. Each observation in column 1 has a natural, real partner in column 2. That is a matched pairs (or paired) design, and it shows up all the time:

DesignWhat is pairedTypical example
Before / afterThe same subject at two timesReaction time before and after a training module
Two treatments, one subjectThe same subject under both conditionsLeft eye vs. right eye; two tires on the same car
Matched subjectsTwo different subjects paired on key traitsTwins; customers matched on age, region, and spend
Two raters, one itemThe same item scored twiceTwo graders scoring the same 30 essays
Not pairedNothing links row i of one group to row i of the other40 people in treatment, 45 different people in control

Here is the beautiful part: a paired analysis is not a new theory. Work out each pair's difference, d = (value 1) − (value 2), and throw away the original columns. Then run an ordinary one sample t-test on the single column of differences against a null value of 0.

H0: μd = 0     Ha: μd ≠ 0     t = d̄ / ( sd / √n )     df = n − 1

Here n is the number of pairs, not the number of measurements. Eight people measured twice give you n = 8 and df = 7, not n = 16.

The method is a one sample t-test, so its conditions are the one sample conditions. But they apply to the column of differences, not to the original two columns. This is the point people most often skip.

ConditionWhat it meansHow to check it
Independence of pairsOne pair's difference tells you nothing about another pair'sA random sample of pairs, or a random order within pairs. The sample is under 10% of the population.
Normality of the differencesThe population of differences is roughly normal, or there are enough pairsA dot plot or histogram of the d column. n ≥ 30 pairs makes mild skew harmless. The two original columns may be skewed; only d matters.
Outliers among differencesNo single pair is driving d̄Scan the d column. One huge difference in a small study can create or erase significance.

In the worked example below there are only eight pairs, so the normality of the differences carries real weight. The eight differences run from −3 to 14 with no gaps or outliers. That fits a population that is about symmetric, so the t method is reasonable. With a clearly skewed difference column, or one full of outliers, and this few pairs, the Wilcoxon signed-rank test of Section 4 would be the safer choice.

Why pairing is worth doing

People differ hugely from one another, and that person to person variation is pure noise when you are trying to detect a treatment effect. Pairing subtracts that noise away. A person who is naturally slow is slow in both columns, so the difference is not affected by how slow they are. What is left in the difference column is the effect plus measurement noise, a much quieter signal to listen to. That is why a paired design can detect an effect with eight subjects that an independent design would miss with forty. Section 4 shows this on real numbers.

A worked example, all the way through

Eight people did a task, and their reaction time in milliseconds was recorded before and after a short training module. It was the same eight people both times, so the data are paired. Test at α = 0.05, two sided, with d = before − after (so a positive d̄ means they got faster).

ParticipantBefore (ms)After (ms)d = before − after
141240012
23853805
3401404−3
44304219
539638214
64214192
74084017
844543510
Mean412.25405.257.00

Step 1: mean difference. The differences add up to 12 + 5 − 3 + 9 + 14 + 2 + 7 + 10 = 56, so d̄ = 56/8 = 7.00 ms. (Happily, this equals 412.25 − 405.25. The mean of the differences is always the difference of the means.)

Step 2: standard deviation of the differences. The deviations from 7 are 5, −2, −10, 2, 7, −5, 0 and 3. Their squares are 25, 4, 100, 4, 49, 25, 0 and 9, which add up to 216.
sd2 = 216 / (8 − 1) = 30.857, so sd = 5.555 ms.

Step 3: standard error. SE = 5.555 / √8 = 5.555 / 2.8284 = 1.964 ms.

Step 4: test statistic and df. t = 7.00 / 1.964 = 3.564, with df = 8 − 1 = 7.

Step 5: p-value and decision. On 7 degrees of freedom, the two sided cutoff at α = 0.05 is 2.365, and the cutoff at α = 0.01 is 3.499. Our 3.564 clears both, so the two sided p-value is a little under 0.01, about 0.009. We reject H0.

Step 6: say it in plain English. "Reaction times got better by an average of 7.0 ms after training. A mean change at least this large, in either direction, would occur in fewer than 1% of studies if training truly had no effect (paired t = 3.56, df = 7, p ≈ 0.009). So there is convincing evidence that reaction time changed." This was a before and after study with no control group, so we should stop short of crediting the training itself. Practice effects and simply getting used to the task are rival explanations that were not ruled out. The test is valid; the claim about cause is limited by the design.

Pairing is decided by the design, not by the data. You cannot look at two columns of equal length, notice they line up nicely and declare them paired. Nor can you unpair truly linked data because the independent test looks tidier. Ask one question of the study: does row 3 of column A have a specific reason, set up ahead of time, to be matched with row 3 of column B? If yes, pair. If the rows could be shuffled without losing information, they are independent.
Interactive Sort ten real study designs into paired and independent, then watch one crossover study's identical numbers analyzed both ways: live sliders for the effect, the spread, the pairing correlation ฯ and the number of pairs drive six computed SVG charts that show exactly what the pairing is worth. Open full ↑
Key points
  • Paired data means every observation has one specific partner: the same subject twice, or subjects matched on purpose.
  • Shrink the pairs to differences and run a one sample t-test on them: t = d̄ / (sd/√n), df = n − 1.
  • n is the number of pairs. Eight people measured twice give df = 7.
  • Check the conditions on the difference column: independent pairs, differences that are about normal (or enough pairs) and no outlier that takes over.
  • Pairing removes the variation from subject to subject, which is why it is far more powerful for the same sample size.

Section 3Two proportions

Diagram comparing event rates between two groups and how their ratio is computed
Reference. Two groups, two event rates. This is the setup behind every comparison of proportions, whether reported as a difference or as a ratio. Source and license: see the figure credits

When the outcome is yes-or-no

Now the outcome is not a number but a group with two levels: clicked or did not click, recovered or did not recover, passed or failed. Each group is summed up by a sample proportion, p̂ = (number of successes) / (group size). "Success" simply labels the outcome you are counting; it does not mean anything cheerful.

H0: p1 − p2 = 0     Ha: p1 − p2 ≠ 0

Here the reference curve is the standard normal, so the statistic is a z, not a t. The reason is that a proportion's standard deviation is fully set by the proportion itself: √(p(1−p)). So once you assume a value for p, there is no separate variance to estimate from data, and no degrees of freedom to lose.

The pooled proportion, and why it appears only in the test

The null hypothesis says the two population proportions are equal to some shared value. If that is true, the best estimate of that shared value uses every observation you have, ignoring the group labels:

p̂pool = (x1 + x2) / (n1 + n2)

And the standard error used for the test is built from that single pooled value:

SEpool = √( p̂pool(1 − p̂pool) × (1/n1 + 1/n2) )     z = (p̂1 − p̂2) / SEpool

A confidence interval, on the other hand, is not built under the null. It is an estimate of whatever the difference really is, so it uses the unpooled standard error, with each group's own proportion. That difference is the most common slip in this section, and Section 5 comes back to it.

The conditions are independence (as before) plus the success-failure condition. The normal approximation only works if you have enough of both outcomes. For the test, check it with the pooled proportion. All four of n1p̂pool, n1(1−p̂pool), n2p̂pool and n2(1−p̂pool) should be at least 10.

A worked example, all the way through

An email is sent in two versions. With Version 1, 45 of 150 people replied. With Version 2, 30 of 160 replied. People were assigned to a version at random. Test at α = 0.05, two sided.

Step 1: the sample proportions.
p̂1 = 45/150 = 0.300   p̂2 = 30/160 = 0.1875
The difference we saw = 0.300 − 0.1875 = 0.1125, which is 11.25 percentage points.

Step 2: the pooled proportion. p̂pool = (45 + 30)/(150 + 160) = 75/310 = 0.24194.

Step 3: check success-failure. 150(0.24194) = 36.3 and 150(0.75806) = 113.7. 160(0.24194) = 38.7 and 160(0.75806) = 121.3. All four are over 10. ✓

Step 4: pooled standard error.
p̂pool(1 − p̂pool) = 0.24194 × 0.75806 = 0.18340
1/150 + 1/160 = 0.006667 + 0.006250 = 0.012917
The product = 0.18340 × 0.012917 = 0.0023688, so SEpool = √0.0023688 = 0.04867.

Step 5: the test statistic. z = 0.1125 / 0.04867 = 2.31.

Step 6: p-value and decision. For the standard normal, the area beyond z = 2.31 in one tail is 0.0104. Doubling it for a two sided test gives p = 0.021. Since 0.021 < 0.05, we reject H0.

Step 7: say it in plain English. "Version 1 drew replies from 30.0% of people, versus 18.8% for Version 2, an 11.3 percentage point difference. If the two versions worked equally well, a gap this large or larger, in either direction, would appear in about 2% of experiments (z = 2.31, p = 0.021). So there is convincing evidence that reply rates differ." Because the assignment was random, reading this as cause is fair here, in a way it was not in Section 2.

QuantityFormulaUsed forIn our example
Differencep̂1 − p̂2Both test and interval0.1125
Pooled p̂(x1+x2)/(n1+n2)Test only0.24194
SE, pooled√(p̂pool(1−p̂pool)(1/n1+1/n2))The z-statistic0.04867
SE, unpooled√(p̂1(1−p̂1)/n1 + p̂2(1−p̂2)/n2)Confidence interval only0.04850
Percentage points are not percent. Going from 18.8% to 30.0% is a rise of 11.3 percentage points. It is also a 60% relative increase (0.1125 / 0.1875 = 0.60). Both numbers are true and describe the same data, and headlines choose whichever sounds larger. State which one you mean, every time.
Interactive Run a two-arm trial patient by patient, watch the gap between two sample proportions bounce around, and see why the test and the confidence interval are built from two different standard errors. Open full ↑
Key points
  • Two proportions use a z statistic, because there are no degrees of freedom to estimate.
  • The pooled proportion is used for the test, because the null claims the proportions are equal.
  • The confidence interval uses the unpooled standard error, because it does not assume the null.
  • Check success-failure: at least 10 successes and 10 failures expected in each group.

Section 4Choosing the right test

Diagram of the null hypothesis significance testing framework
Reference. The framework for testing a null hypothesis. Every method in this chapter is the same skeleton with a different standard error bolted on. Source and license: see the figure credits

Two questions get you there

People often try to memorize a dozen tests. You do not need to. In the two sample world, two questions settle it almost every time.

Question 1: what kind of outcome did you measure? If each subject gave a number you could sensibly average, such as minutes, dollars or millimeters of mercury, you are comparing means. If each subject gave a yes or no label that you are counting, you are comparing proportions. (A satisfaction rating from 1 to 5 is a true gray area. Treating it as a number is common and most often fair, but say what you did.)

Question 2: how are the two groups related? If every value in one group has a specific partner in the other, the data are paired. Otherwise, they are independent. You answer this by reading the study design, never by staring at the numbers.

OutcomeGroup relationshipTestStatisticReference curve
NumericIndependentTwo-sample (Welch) t-test(x̄1−x̄2)/√(s12/n1+s22/n2)t, Welch df
NumericPairedPaired t-testd̄/(sd/√n)t, df = n−1
Yes/noIndependentTwo-proportion z-test(p̂1−p̂2)/SEpoolStandard normal
Yes/noPairedMcNemar's testBuilt only from the discordant pairsChi-square, df = 1
Numeric, badly skewed / tiny nIndependentWilcoxon rank-sum (Mann-Whitney)Rank-basedIts own distribution
Numeric, badly skewed / tiny nPairedWilcoxon signed-rankRank-basedIts own distribution
Yes/no, small countsIndependentFisher's exact testExact enumeration(exact)

What the choice actually costs you

This is not bookkeeping, because the wrong choice changes the answer. Take the same eight people from Section 2, and pretend, wrongly, that the "before" and "after" columns came from two unrelated groups of eight people. The two column means do not change: 412.25 and 405.25, a difference of 7.00 ms. But now the spread from person to person is back in the denominator. Working from those columns, sbefore = 19.33 and safter = 19.08, so

SE = √(19.332/8 + 19.082/8) = √(46.71 + 45.49) = √92.20 = 9.602

t = 7.00 / 9.602 = 0.73, df ≈ 14, p ≈ 0.48

The same seven millisecond effect goes from p ≈ 0.009 (paired, correct) to p ≈ 0.48 (independent, wrong). It goes from convincing evidence to nothing at all. The paired standard error was 1.96 ms, and the independent one was 9.60 ms, nearly five times larger. That is because it is dominated by the fact that person 8 is simply slower than person 2. Pairing sweeps that irrelevant fact out of the math. Analyze paired data as independent, and you will often fail to find effects that are really there.

The reverse mistake is worse. If the data are truly independent, there is no way to line them up into pairs. Forcing a pairing, by sort order or by row number in a spreadsheet, makes up a relationship that does not exist. It gives a p-value with no meaning at all.

Three decisions to make before you look

Fix these ahead of time, because deciding them after seeing the data makes the p-value worthless:

The design chooses the test; the p-value never does. If two methods give different answers on the same data, that is not a menu, because one of them is wrong for that design. Write down which test the design calls for before you work anything out. Stick to it, whichever way the number lands.
Interactive Walk a decision tree from a study's description to the right two-sample test, then watch the test at the end of your path run live on the real data beside the test you would have reached by answering differently, and simulate thousands of studies to see what the last question is actually worth. Open full ↑
Key points
  • Two questions choose the test: a number or a yes or no outcome, and independent or paired groups.
  • Paired numbers → paired t. Independent numbers → Welch t. Independent yes or no → two-proportion z. Paired yes or no → McNemar.
  • Analyzing paired data as independent inflates the standard error and hides real effects.
  • Fix your direction, your α and your number of comparisons before seeing results.

Section 5Two-sample confidence intervals

Illustration of a confidence interval around an estimate
Reference. A confidence interval around an estimate. It shows the range of believable values that a point estimate alone cannot show. Source and license: see the figure credits

From a verdict to a measurement

A test gives a verdict: reject, or fail to reject. That is a thin answer. It does not say how big the difference is, and "significant" and "important" are fully different words. A confidence interval for the difference answers the better question: how big, give or take how much? And every two sample interval in this chapter has one shape:

(point estimate) ± (critical value) × (standard error)

ComparisonPoint estimateStandard errorCritical value
Two independent meansx̄1 − x̄2√(s12/n1 + s22/n2)t*, Welch df
Paired meansd̄sd/√nt*, df = n − 1
Two proportionsp̂1 − p̂2√(p̂1(1−p̂1)/n1 + p̂2(1−p̂2)/n2): unpooledz* (1.96 for 95%)

The product of the last two columns is the margin of error. Nothing else changes from method to method.

Worked: the interval for Section 1's data

Go back to the coaching study: x̄1 − x̄2 = 6.5, SE = 3.4274 and df ≈ 24.9.

Step 1: critical value. For 95% confidence with about 25 degrees of freedom, t* ≈ 2.06. (Rounding df down to 24 gives 2.064, and the difference cannot be seen at two decimals.)

Step 2: margin of error. 2.06 × 3.4274 = 7.06 points.

Step 3: the interval. 6.5 − 7.06 = −0.56 and 6.5 + 7.06 = 13.56, giving (−0.56, 13.56) points.

Step 4: read it. The interval contains 0, so "no difference" is among the believable values. That matches the earlier decision to fail to reject at α = 0.05 exactly. But it says far more than the test did. It says Format A could believably be half a point worse, or as much as thirteen and a half points better. That is a huge range. The honest conclusion is not "the formats are the same." It is "this study was too small to tell us anything useful, and it should be repeated with more people."

The other two examples work the same way. For the paired reaction times: 7.00 ± 2.365 × 1.964 = 7.00 ± 4.65, giving (2.35, 11.65) ms. That is fully above zero, which matches p ≈ 0.009. For the two email versions, use the unpooled SE = √(0.300×0.700/150 + 0.1875×0.8125/160) = √(0.001400 + 0.000952) = 0.04850. The interval is 0.1125 ± 1.96 × 0.04850 = 0.1125 ± 0.0951, giving (0.017, 0.208). That is between 1.7 and 20.8 percentage points, all positive.

Duality, and the one place it leaks

For the two t methods, the interval and the two sided test are two views of one calculation. A 95% interval that leaves out 0 matches exactly a two sided test that rejects at α = 0.05. An interval that contains 0 matches exactly a test that fails to reject. Both use the same point estimate, the same standard error and the same critical value.

For two proportions, this match is only approximate, because the test uses the pooled standard error and the interval uses the unpooled one. When a result sits very near the edge, the two can disagree. You might get a p-value of 0.048 alongside an interval whose lower limit is a hair below zero. Neither is a mistake; they are answering slightly different questions. Report both, and describe the finding as borderline, which is what it is.

What a confidence interval actually means

Here is the sentence to memorize, because the tempting version is wrong. The parameter μ1 − μ2 is a fixed, unknown number. Your interval is what varied at random, since a different sample would have given a different one. So the 95% describes the method. If you repeated this whole study without end, about 95% of the intervals it made would cover the true difference. It does not say there is a 95% chance that the true difference lies in the one interval you happen to be holding. That interval either covers the parameter or it does not, because the coin has already landed.

The p-value needs the same care. p = 0.021 means this: if the null were true, data at least this extreme would occur about 2.1% of the time. It is not the probability that the null is true, not the probability that the result was a fluke and not a measure of effect size. A trivial difference becomes "significant" with a large enough sample, and a large difference stays "not significant" with a small one. This is just why you report the interval alongside the p-value. The p-value tells you whether you can see the effect, and the interval tells you whether it is worth caring about.

"Zero is in the interval" is not "the groups are the same." An interval of (−0.56, 13.56) and an interval of (−0.20, 0.25) both contain zero, and both fail to reject. But the first is an admission that we do not know. The second is real evidence that any difference is tiny. Only the width of the interval tells you which one you have, and the test statistic alone never will.
Interactive Build a confidence interval for a difference between two groups from live samples, watch it widen with confidence and narrow with sample size, and work out what it really means when the interval covers zero. Open full ↑
Key points
  • Every two sample interval is (estimate) ± (critical value)(SE). Only the SE and the critical value change.
  • Use t* for means (Welch df, or n−1 when paired) and z* for proportions, with the unpooled SE.
  • An interval that contains 0 matches a two sided test that fails to reject. The match is exact for t methods and approximate for proportions.
  • The 95% belongs to the method over the long run, not to the single interval in front of you.
  • A p-value is not the probability that the null hypothesis is true.

The chapter in one breath

  • A two-sample test asks whether a gap seen between two groups is larger than chance alone would easily produce.
  • For independent means, variances add: SE = √(s12/n1 + s22/n2), and t = (x̄1 − x̄2)/SE on Welch degrees of freedom.
  • For paired data, shrink each pair to a difference and run a one sample t-test on the differences with df = n − 1, where n counts pairs.
  • Pairing removes the variation from subject to subject. The same 7 ms effect gave p ≈ 0.009 when paired and p ≈ 0.48 when analyzed (wrongly) as independent.
  • For two proportions, use a z statistic, with the pooled proportion in the test and the unpooled SE in the interval. Check success-failure.
  • The design picks the test: a number vs. a yes or no outcome, and independent vs. paired groups. Decide before any math.
  • Every two sample confidence interval is (estimate) ± (critical value)(SE). It reports the size of the effect that the test only votes on.
  • The 95% describes the method over the long run. A p-value is the probability of the data given the null, never the probability that the null is true.

ReferenceWords worth knowing

A quick reference for the terms in this chapter. Skim it now, or come back whenever a word trips you up.

Alternative hypothesis (Ha)
The claim that there is a difference. In this chapter, it is most often μ1 − μ2 ≠ 0 or p1 − p2 ≠ 0.
Confidence interval
A range of believable values for a parameter, built as (estimate) ± (critical value)(standard error). Its confidence level describes how often the method succeeds over the long run.
Degrees of freedom
The number that sets the shape of a t curve. It is n − 1 for a paired test, and Welch's approximation for two independent means.
Independent samples
Two groups in which no subject appears twice and no observation is naturally matched to another.
Margin of error
The half width of a confidence interval: the critical value times the standard error.
Matched pairs
A design in which each observation in one condition has one specific partner in the other: the same subject twice, or subjects matched on purpose.
Nonparametric test
A method that does not assume a normal population and most often works from ranks. Examples are the Wilcoxon rank-sum and Wilcoxon signed-rank tests.
Null hypothesis (H0)
The claim of no difference between the two populations, against which the data are weighed.
Paired t-test
A one sample t-test applied to the differences within pairs, testing μd = 0.
Point estimate
The single best guess at a parameter from the sample. Here it is x̄1 − x̄2, d̄ or p̂1 − p̂2.
Pooled proportion
(x1 + x2)/(n1 + n2), the shared proportion estimated under the null. It is used in the two-proportion test only.
Pooled two-sample t-test
The older version that assumes equal population variances and combines them into one estimate. Welch's test is the safer default.
p-value
The probability of seeing data at least as extreme as yours if the null hypothesis were true. It is not the probability that the null is true.
Sampling distribution
The distribution of a statistic across all possible samples. For a difference of means, it is about a t curve centered on the true difference.
Significance level (α)
The cutoff, fixed ahead of time, at which a p-value counts as convincing. Put another way, it is the accepted rate of Type I error.
Standard error
The estimated standard deviation of a statistic: how much the difference between the two samples would wobble from study to study.
Success-failure condition
The rule of at least 10 expected successes and 10 expected failures in each group before trusting the normal approximation for proportions.
t-distribution
A bell curve with heavier tails than the normal, used when the standard deviation is estimated from data. It comes closer and closer to the normal as df grows.
Test statistic
(Observed − hypothesized) divided by the standard error: the difference seen, given in standard errors.
Two-sample t-test
The test of μ1 − μ2 = 0 from two independent samples of a numeric outcome.
Type I error
Rejecting a null hypothesis that is actually true: a false positive. Its long run rate is α.
Welch's t-test
The two-sample t-test that does not assume equal variances. It uses a formula that approximates the degrees of freedom, and it is the advised default.

Check yourself

1. A study measures cholesterol in 40 people before a diet and in the same 40 people after it. A coworker runs a two-sample t-test with n1 = n2 = 40. What is wrong, and what should be done instead?
The samples are not independent. They are the same 40 people twice, so this is a matched pairs design. Work out the 40 differences within each person, and run a paired t-test on them with df = 39. Treating paired data as independent leaves all the variation from person to person in the standard error. That inflates it and makes a real effect much harder to detect.
2. Two independent samples have s1 = 6 with n1 = 9, and s2 = 8 with n2 = 16. Work out the standard error of the difference in means.
SE = 2.828. s12/n1 = 36/9 = 4; s22/n2 = 64/16 = 4; the sum = 8; √8 = 2.828. Note that the variances are added, never the standard deviations. Adding 6 and 8 would be a serious error.
3. A two sided test gives p = 0.03 at α = 0.05. A classmate says, "There is a 3% chance the null hypothesis is true." Correct them exactly.
The p-value is the probability of data at least this extreme given that the null is true. It is not the probability that the null is true. The null is either true or false, and it has no probability in this framework. The correct reading: if the two populations really were the same, results this extreme would occur about 3% of the time.
4. In the paired reaction time example, d̄ = 7.00 ms, sd = 5.555 and n = 8. Work out t again, and give the degrees of freedom.
t = 3.56 with df = 7. SE = 5.555/√8 = 5.555/2.8284 = 1.964, and t = 7.00/1.964 = 3.564. The degrees of freedom are n − 1 = 7, where n is the number of pairs. It is not 16 measurements, and not df = 15.
5. Why does the two-proportion test use a pooled proportion while the confidence interval does not?
The test is worked out assuming the null is true. The null says both populations share one proportion, so the best estimate of it uses all the data combined. A confidence interval makes no such assumption. It estimates whatever the difference really is, so each group adds its own p̂ to the standard error.
6. Group 1 has 24 successes in 80. Group 2 has 12 successes in 60. Work out the two sample proportions and the pooled proportion, and check the success-failure condition.
p̂1 = 0.300, p̂2 = 0.200 and p̂pool = 36/140 = 0.2571. The condition is met. The expected counts are 80(0.2571) = 20.6 and 80(0.7429) = 59.4, and 60(0.2571) = 15.4 and 60(0.7429) = 44.6. All four are at least 10, so the normal approximation is safe.
7. A 95% confidence interval for μ1 − μ2 is (2.1, 8.7). State two things you can conclude, and one common statement you must avoid.
Conclude: (a) zero is not in the interval, so a two sided test at α = 0.05 would reject the null; (b) the believable size of the difference runs from about 2 to about 9 units, with group 1 larger. Avoid: "there is a 95% chance the true difference is between 2.1 and 8.7." The parameter is fixed, and the 95% refers to how the method performs across repeated studies over the long run.
8. Explain why a paired design can find an effect that an independent design of the same size misses.
Pairing subtracts out the variation from subject to subject, which is noise as far as the treatment effect goes. Each person serves as their own control, so a naturally high or low starting level cancels in the difference. The result is a much smaller standard error. In the chapter's example, it was 1.96 ms paired versus 9.60 ms unpaired, which shifted p from about 0.009 to about 0.48 for the same 7 ms effect.
9. For two independent means, x̄1 − x̄2 = 5.0, SE = 2.0 and df ≈ 30, so t* = 2.042. Build the 95% confidence interval, and state the test decision it implies.
(0.92, 9.08), and the two sided test rejects H0 at α = 0.05. Margin of error = 2.042 × 2.0 = 4.084; 5.0 − 4.084 = 0.916 and 5.0 + 4.084 = 9.084. Because zero lies outside the interval, "no difference" is not a believable value at this confidence level.
10. When would you reach for a Wilcoxon rank-sum test instead of a two-sample t-test, and when for McNemar's test?
Wilcoxon rank-sum: a numeric outcome and independent groups, but small samples with clear skew or outliers, so the normality condition fails. McNemar: a yes or no outcome measured on paired subjects. The two-proportion z-test assumes independent groups and would be wrong for paired yes or no data.
11. A researcher gets a two sided p of 0.08. Then she switches to a one sided test to get p = 0.04 and declares significance. What is the problem?
The direction of the test must be fixed before seeing the data. Choosing it afterward doubles the real false positive rate. A one sided test is fair only when a difference the other way would be of no interest at all, and only when that choice is registered ahead of time (pre-registered). Switching after the fact (post hoc) makes the reported p-value meaningless.
12. Interval A is (−0.56, 13.56), and interval B is (−0.20, 0.25). Both contain zero, so both tests fail to reject. Why are these two results very different for science?
Interval A is wide. It fits with no effect but also with a large effect, so the study simply tells us little and should be repeated with a bigger sample. Interval B is narrow and pinned near zero, which is real evidence that any true difference is too small to matter. "Fail to reject" is the same in both cases. Only the interval shows the difference between not knowing and knowing exactly.