When two groups in an experiment finish with different averages, we need a way to tell whether the treatment actually worked or random assignment just happened to put the strongest people into one group.
1
Shuffling Cards to Test the Null Hypothesis
Suppose six volunteers are randomly split into two groups of three and study a list of 20 words: the New Method group remembers 7,10, and 13 words, while the Old Method group remembers 2,5, and 8 words. We want to find out whether the 5-word difference between their averages could easily happen just by the luck of the random split.
Shuffling Cards Under the Null Hypothesis
Text solution
Find the observed difference in averagesSubtract the Old Method average from the New Method average to find the difference in the actual experiment.
Observed difference=37+10+13−32+5+8=10−5=5 words
Keep each score written on its card under H0Assume the new method has no effect, so every volunteer would have remembered the exact same number of words in either group, giving six fixed index cards.
vs.method has no effectH0:μnew−μold=0new method increases averageHa:μnew−μold>0Deck: {2,5,7,8,10,13}
Shuffle and deal two fake piles of 3Deal the six cards into two random groups of three and subtract their averages to see one difference created by pure luck.
Fake New {2,8,10} vs. Fake Old {5,7,13}:32+8+10−35+7+13=6.67−8.33=−1.67
2
Finding an Exact P-Value from All Possible Deals
One or two shuffles show that random deals usually mix high and low cards to give a difference near 0. To find the exact probability of getting a difference of +5 words or more by luck alone, we count how many of all possible three-card deals reach +5 or higher.
Finding a P-Value from All Possible Deals
Text solution
Count all possible dealsUse combinations to count how many ways 3 cards can be chosen from the 6 for the left pile (which automatically leaves the remaining 3 for the right pile).
6 choose 3=3×2×16×5×4=20 possible deals
Find every deal at +5 or higherCheck which deals put enough big numbers into the left pile to reach our observed difference of +5.00 or higher.
{7,10,13} vs. {2,5,8}:10.00−5.00=+5.00{8,10,13} vs. {2,5,7}:10.33−4.67=+5.67
Divide the tail count by the total dealsCount only the right tail for a one-sided test, or include the two opposite deals on the left tail (−5.00 and −5.67) for a two-sided test.
Since 0.10>0.05, we do not reject H0; with only 20 total deals, even the single most extreme deal (+5.67) gives a one-sided p-value of 201=0.05.
Try swapping cards between the two piles to see how the 20 possible deals build the full distribution.
Most deals mix high and low cards to stay near zero, and only grouping the biggest cards in one pile reaches the far ends.
3
Simulating Shuffles for Larger Groups
With only six volunteers, there aren't enough possible deals to make a lucky split rare. If we run the same memory experiment with 30 volunteers split into two groups of 15 and observe a 4.2-word difference, we want to find the p-value when there are too many possible deals to list every one.
Simulating Shuffles for Larger Groups
Text solution
Find the observed difference in sample meansSubtract the Old Method average from the New Method average for the 30 volunteers, where xˉ stands for a group's sample average.
difference in sample averagesxˉnew−xˉold=4.2 words
Simulate 10,000 random dealsBecause 30 choose 15 is over 155 million deals, have a computer randomly shuffle the 30 cards into two piles of 15 and record the difference in averages 10,000 times.
Divide simulated tail deals by 10,000Count how many of the 10,000 shuffled differences reach +4.2 or higher and compare that fraction with α=0.05.
p-value≈10,00012=0.0012<0.05
Because 0.0012<0.05 and volunteers were randomly assigned to the two groups, we reject H0 and conclude that the new memory method caused the higher average recall.
4
Shuffling Yes-or-No Cards for Two Proportions
Now suppose each person's outcome isn't a number to average, but a simple Yes or No. In a trial of 40 migraine patients randomly split into 20 on a new medication and 20 on a placebo, 14 of 20 in the medication group and 6 of 20 in the placebo group report their headache is gone after an hour, and we want to test whether that 40-percentage-point difference could happen by luck.
Shuffling Yes-or-No Cards for Two Proportions
Text solution
Find the observed difference in sample proportionsSubtract the placebo group's fraction of Yeses from the medication group's fraction, where p^ stands for a group's sample proportion.
difference in sample proportionsp^med−p^placebo=2014−206=0.70−0.30=+0.40
Combine all YES and NO cards under H0Under H0:pmed−pplacebo=0, the 20 people whose headaches went away would have said Yes regardless of which pill they got, giving a fixed deck of 40 cards.
Total YES cardsTotal NO cards=14+6=20,=6+14=20
Shuffle 10,000 times and count the tailDeal 20 cards to Fake Medication and 20 to Fake Placebo 10,000 times, subtract the fake group proportions on each deal, and find the fraction reaching +0.40 or higher.
p-value≈10,000130=0.013<0.05
Because 0.013<0.05, we reject H0 and conclude that the medication caused a higher proportion of patients to become headache-free.
5
Medians and Random Samples vs. Random Assignment
When we compare workers' incomes from two cities using independent random samples and one sample happens to include a billionaire, we face two new questions: how to keep that single outlier from throwing off the group averages, and what conclusion a small p-value supports when nobody was randomly assigned to live in either city.
Medians and Random Samples vs. Random Assignment
Text solution
Shuffle and subtract sample mediansDeal all income cards into two fake piles matching the original sample sizes and subtract the middle incomes (medians) of the two piles on each shuffle.
Shuffled difference=MedianFake A−MedianFake B
Match the conclusion to how the data were collectedA small p-value means random luck alone is an unlikely explanation, but whether you can claim cause and effect depends on whether the groups came from random assignment or random sampling.
Drag one income up into an outlier to compare what happens to the randomization distribution for means versus medians.
See how one extreme card pulls the shuffled means toward whichever pile gets it, while the shuffled medians and their tail barely move.
Key concepts
Every two-group randomization test is the same card-dealing experiment underneath: under H0, the group labels do nothing, so each outcome stays written on its index card. We combine all the cards into one deck, deal them into two fake groups matching the original sample sizes, and check what fraction of deals give a difference at least as extreme as our real data.
What we compute after each deal comes straight from the type of card in the deck:
Numerical cards without extreme outliers
(such as words remembered, {7,10,13} vs. {2,5,8}): subtract the group averages, xˉnew−xˉold=10−5=5.
Numerical cards with an extreme outlier
(such as city incomes that include a billionaire): do not use group averages, because the outlier pulls up the average of whichever pile gets that card; subtract the middle values instead, MedianA−MedianB.
Yes-or-No cards
(such as 2014 vs. 206 headache-free): combine all Yeses (14+6=20 YES cards) and all Nos (6+14=20 NO cards) into one deck and subtract the group proportions, p^med−p^placebo=0.70−0.30=+0.40.
How we count the deals depends only on the group sizes:
Small groups
(such as 6 cards split into 3 and 3, giving 6 choose 3=20 deals): list every possible deal for the exact p-value (202=0.10 one-sided for Ha:μnew−μold>0, or 204=0.20 two-sided for Ha:μnew−μold=0). Watch out for very small sample sizes where even the single most extreme deal has total deals1>α, making it impossible to reject H0.
Larger groups
(such as 30 cards split into 15 and 15, where 30 choose 15>155 million): do not try to list every combination; run 10,000 computer shuffles and divide the tail count by 10,000 (such as 10,00012=0.0012).
Finally, when p<α, look back at how the groups were formed before writing your conclusion: random assignment to treatments lets you conclude the treatment caused the difference, whereas independent random samples from two populations let you conclude there is a real difference between the populations without claiming cause and effect.
6
Practice
1
Six seedlings are randomly assigned to two groups of 3: Fertilizer A produces growth of 14, 18, and 22 cm, while Fertilizer B produces growth of 8, 12, and 16 cm. State the null and alternative hypotheses to test whether Fertilizer A increases average growth, find the observed difference in means (A minus B), and find the difference in means for a random shuffle that deals 8, 18, and 22 to Fake A and 12, 14, and 16 to Fake B.
Under H0, does each seedling's growth measurement change when it is dealt into a fake group, or does it stay fixed on its card?
The hypotheses compare the true group averages to test whether Fertilizer A increases growth:
vs.H0:μA−μB=0Ha:μA−μB>0
For the real experiment, average each group of 3 and subtract B from A:
xˉA−xˉB=314+18+22−38+12+16=18−12=6 cm
For the shuffled deal, average Fake A and Fake B and subtract in the same order (A minus B; watch out for subtracting Fake B minus Fake A, which reverses the sign to give −2 cm):
xˉFake A−xˉFake B=38+18+22−312+14+16=16−14=2 cm
2
Using the six seedling measurements from p1 (8, 12, 14, 16, 18, 22) split into two piles of 3, find the total number of possible deals, identify every deal that produces a difference (Fake A minus Fake B) of at least +6 cm, and calculate both the one-sided (Ha:μA−μB>0) and two-sided (Ha:μA−μB=0) exact p-values.
Start with the single deal that puts the three largest cards in Fake A, then check which one-card swap still leaves the difference at +6 cm or higher.
The total number of ways to choose 3 of the 6 cards for Fake A is:
6 choose 3=3×2×16×5×4=20 possible deals
Only 2 deals put enough large cards in Fake A to reach a difference of +6 cm or higher (be careful not to count only deals strictly greater than +6 cm, which leaves out the observed deal at +6.00 cm and gives 201=0.05):
{14,18,22} vs. {8,12,16}:18.00−12.00=+6.00 cm{16,18,22} vs. {8,12,14}:18.67−11.33=+7.33 cm
Dividing by the 20 possible deals gives the one-sided p-value, and including the 2 opposite deals at −6.00 cm and −7.33 cm gives the two-sided p-value:
Fifty people with insomnia are randomly assigned to two groups of 25: a sleep aid group where 18 of 25 fall asleep within 30 minutes, and a placebo group where 9 of 25 do. Describe the deck of cards and dealing procedure used to test H0:paid−pplacebo=0 against Ha:paid−pplacebo>0, find the observed difference in proportions, and find the p-value if 85 of 10,000 computer shuffles produce a difference of at least that size.
Under H0, how many of the 50 people in total were going to fall asleep within 30 minutes regardless of which group they were dealt into?
Combine all 50 outcomes into a deck of 50 index cards with 18+9=27 marked YES and 25+25−27=23 marked NO, shuffle the deck, and deal 25 cards to Fake Sleep Aid and 25 to Fake Placebo.
Subtract the sample proportions of YES cards (don't just subtract the counts 18−9=9 without dividing by the group size of 25):
p^aid−p^placebo=2518−259=0.72−0.36=+0.36
Because Ha:paid−pplacebo>0 is one-sided (don't double the tail count to 10,000170=0.017), divide the 85 right-tail shuffles by 10,000:
p-value=10,00085=0.0085
4
An economist takes independent random samples of 20 homes from Town X and 20 homes from Town Y to test whether home prices differ. One sampled home in Town X is a $45 million estate, while all other 39 homes cost between $250,000 and $600,000. The observed difference in sample medians (Town X minus Town Y) is +$55,000. In 10,000 random shuffles of all 40 prices into two piles of 20, 140 shuffles give a median difference of +$55,000 or higher and 130 shuffles give −$55,000 or lower. Explain why medians are shuffled instead of means, find the two-sided p-value, and state what conclusion is justified at α=0.05.
Because testing whether prices differ is two-sided (Ha: the median prices of all homes in Town X and Town Y are different), add both tails before dividing by 10,000 (using only the right tail gives the one-sided value 10,000140=0.014).
Does testing "whether home prices differ" check one tail or both tails, and how were the two groups of 20 homes obtained?
Medians are shuffled instead of means because the single $45 million estate is an extreme outlier that would pull up the average of whichever pile it landed in.
Because testing whether prices differ is two-sided (Ha: the median prices of all homes in Town X and Town Y are different), add both tails before dividing by 10,000 (using only the right tail gives the one-sided value 10,000140=0.014):
p-value=10,000140+130=10,000270=0.027
Since 0.027<0.05, we reject H0 and conclude there is a real difference in median home prices between Town X and Town Y, but we cannot claim that being in Town X causes higher prices because the homes came from two random samples rather than random assignment.
5
A researcher plans to test a new coaching method at α=0.01 using a one-sided randomization test (Ha:μnew−μold>0) with 8 athletes split into two groups of 4. Explain why this experiment can never reject H0 at α=0.01 no matter how large the observed difference is, and find the smallest even number of athletes (split into two equal groups) needed so that rejecting H0 at α=0.01 is possible.
If the 4 highest-scoring athletes all land in the New Method group, that single most extreme deal is 1 out of how many total possible deals?
With 8 athletes split into two groups of 4, the total number of possible deals is:
8 choose 4=4×3×2×18×7×6×5=70 possible deals
Even if the experiment produces the single most extreme deal possible, the smallest possible one-sided p-value is 701≈0.0143, which is greater than α=0.01, so H0 can never be rejected.
Trying the next even number of athletes, 10 split into two equal groups of 5 (don't pick 9 athletes, which cannot be split into two equal groups), gives:
10 choose 5=5×4×3×2×110×9×8×7×6=252 possible deals
Since 2521≈0.0040≤0.01, the smallest even number of athletes needed is 10.