MATH 3 • STATISTICS & PROBABILITY

Comparing Groups via Simulation — I can compare two groups using simulated variability and decide whether a difference is meaningful at my level.

Use randomization to determine whether a difference between two groups is real or just due to chance.

Historical Context & Motivation

Whenever scientists, doctors, or data analysts compare two groups — say, a new medication versus a placebo, or test scores from two different schools — they face a fundamental question: Is the difference I see real, or could it just be random noise? For centuries, researchers struggled with this question because they lacked tools to measure the role of chance. The development of simulation-based inference gave us a powerful, intuitive way to answer it — by literally recreating what random chance looks like and checking whether the real data fits that pattern.

1710
Arbuthnot's Birth Ratio Test
John Arbuthnot compared the ratio of male to female births over 82 years in London. He argued that the consistent excess of male births was too unlikely to be chance alone — an early informal hypothesis test.
1935
Fisher's Randomization Test
Ronald Fisher proposed the randomization test for experiments. He showed that you could assess significance by re-shuffling group labels and comparing the observed result to shuffled outcomes — the theoretical foundation for simulation tests.
1969
Monte Carlo Methods Go Mainstream
With growing computer power, statisticians began using Monte Carlo simulations — thousands of random re-shuffles generated electronically — making randomization tests practical for everyday data analysis.
2000s–present
Simulation in the Classroom
Statistics education shifted to emphasize simulation-based reasoning before formal formulas. Tools like applets and coding environments now let students build intuition about variability before encountering z-scores and t-tests.

The core question this lesson addresses is deceptively simple: if you observe a difference between two groups, how do you know it isn't just a fluke? Simulation gives you a way to visualize what "typical random differences" look like, so you can judge whether your observed difference stands out from the crowd.

Core Principles & Definitions

Before diving into simulations, you need to understand a handful of foundational ideas. These principles form the logic chain that makes simulation-based comparison work.

1

Observed Difference

The actual numerical gap between the two groups' statistics (usually their means or proportions). This is the value you want to evaluate — for example, "Group A scored 6 points higher than Group B on average."
2

Null Hypothesis (H₀)

The assumption that there is no real difference between the groups — any gap you see is purely due to random variation. The simulation is built around this assumption.
3

Random Reassignment (Shuffling)

If the null hypothesis were true, group labels wouldn't matter. So we randomly shuffle who belongs to which group and recalculate the difference. Each shuffle produces one simulated result under chance alone.
4

Simulated Distribution

After many shuffles (often 1,000 or more), you collect all the simulated differences into a dot plot or histogram. This distribution shows what differences typically occur by chance.
5

Statistical Significance

If the observed difference falls far in the tail of the simulated distribution — meaning very few random shuffles produced a gap that large — the result is considered statistically significant. You have evidence that the difference is not just chance.
KEY TAKEAWAY
Think of simulation like a courtroom trial. The null hypothesis is "innocent until proven guilty" — we assume no real difference exists. The simulation generates thousands of outcomes under this assumption (the jury hears all the "what if it were just chance?" scenarios). If your observed difference is so extreme that it almost never shows up among those random outcomes, the evidence is strong enough to reject the null — like a verdict of "guilty beyond reasonable doubt."

Visual Explanation — The Simulation Process

The diagram below walks through the entire simulation workflow from start to finish. Follow the flow from left to right: you begin with your real data, generate many random reshuffles, build a distribution of simulated differences, and then locate your observed difference on that distribution to make a judgment.

The histogram shows 1,000 simulated differences produced by random shuffling under the null hypothesis. The dashed red line marks the observed difference of 8.75. Because only about 2% of simulated differences are that extreme, the result is statistically significant — the data provides evidence against the null hypothesis.

Notice how the simulated distribution is roughly centered at zero. This makes sense: if group membership truly doesn't matter, shuffling should produce differences that bounce around zero — sometimes Group A's mean is a little higher, sometimes Group B's is. The farther your observed difference sits from the center, the stronger your evidence that something real — not just chance — is going on.

Mathematical Framework

Although simulation is built on re-shuffling rather than formulas, several key quantities guide the process. Understanding these will help you set up, run, and interpret any simulation-based comparison.

OBSERVED DIFFERENCE IN MEANS
D_obs = x̄_A − x̄_B
where x̄_A is the mean of Group A and x̄_B is the mean of Group B. This single number summarizes how far apart the two groups are. For proportions, replace means with p̂_A and p̂_B.
SIMULATED DIFFERENCE (ONE SHUFFLE)
D_sim = x̄_shuffled A − x̄_shuffled B
After randomly reassigning all data values to two groups of the same original sizes, compute the difference in means for that particular shuffle. Repeat this process many times (typically 1,000 to 10,000) to build the null distribution.
ESTIMATED P-VALUE
p-value ≈ (number of D_sim values ≥ |D_obs|) ÷ (total number of simulations)
The p-value estimates how often chance alone produces a difference at least as extreme as the one you observed. A small p-value (commonly below 0.05) suggests the observed difference is unlikely under the null hypothesis.
⚠️ Two-Sided vs. One-Sided
If you only care whether Group A is higher than Group B, count simulated differences ≥ D_obs (one-sided). If you care about any large difference in either direction, count simulated differences with |D_sim| ≥ |D_obs| (two-sided). In this course, assume two-sided unless told otherwise.

Interpreting the Simulated Distribution

Once you have a simulated distribution of differences, the critical step is placing your observed difference on it and deciding what it means. The diagram below shows three different scenarios — each with the same null distribution but a different observed difference — to illustrate how location affects your conclusion.

Three scenarios show how the same simulated null distribution leads to different conclusions depending on where the observed difference falls. Scenario A (difference of 1.2) sits in the middle — not significant. Scenario B (5.0) lands near the boundary — borderline. Scenario C (8.75) is deep in the tail — statistically significant.

The threshold of p < 0.05 is the most commonly used cutoff in practice, but it is a convention rather than a law of nature. Some fields use stricter thresholds (like p < 0.01 in physics) while others accept p < 0.10 for exploratory studies. The key idea remains the same: the smaller the p-value, the stronger the evidence that the observed difference is not due to random chance.

💡 Important Language
When p ≥ 0.05, you say "we fail to reject H₀" — not "we accept H₀." Failing to find evidence of a difference is not the same as proving there is no difference. Similarly, a significant result means the difference is unlikely due to chance — it does not automatically mean it is large or practically important.

Worked Example — Sleep and Test Scores

A teacher wants to know whether students who sleep at least 8 hours the night before a test score higher than students who sleep fewer than 8 hours. She collects the following data from 10 students.

Test scores grouped by sleep duration
GroupScoresMean
≥ 8 hours (n = 5)88, 92, 85, 90, 9590.0
< 8 hours (n = 5)78, 82, 80, 75, 8580.0
Is the 10-point difference meaningful?
1
Step 1 — Calculate the Observed DifferenceCompute D_obs = x̄(≥ 8 hrs) − x̄(< 8 hrs) = 90.0 − 80.0.
D_obs = 10.0 points
2
Step 2 — State the Null HypothesisH₀: Sleep duration has no effect on test scores. Any difference in means is due to random variation. Under H₀, it wouldn't matter which group each score belongs to.
3
Step 3 — Simulate by ShufflingPool all 10 scores: {88, 92, 85, 90, 95, 78, 82, 80, 75, 85}. Randomly assign 5 to "Group A" and 5 to "Group B." Calculate the difference in means for that shuffle. For example, one shuffle might give Group A = {78, 92, 85, 80, 95} (mean = 86.0) and Group B = {88, 82, 90, 75, 85} (mean = 84.0), yielding D_sim = 2.0.
4
Step 4 — Repeat 1,000 TimesUsing technology (a calculator app, spreadsheet, or online simulator), perform 1,000 random shuffles and record each D_sim. Plot these 1,000 values in a histogram to visualize the null distribution.
5
Step 5 — Count Extreme ValuesCount how many of the 1,000 simulated differences have |D_sim| ≥ 10.0. Suppose 18 out of 1,000 shuffles produced a difference of 10.0 or more (in either direction).
Estimated p-value = 18 ÷ 1000 = 0.018
6
Step 6 — Make a DecisionSince p = 0.018 < 0.05, we reject H₀. There is statistically significant evidence that the sleep group scored higher than the non-sleep group, beyond what random chance alone would explain.
The 10-point difference is statistically significant at the 0.05 level.

Strengths and Limitations of Simulation

Comparing simulation-based inference strengths and limitations
StrengthsLimitations
Intuitive — you can see what chance looks like, no complex formulas needed.Results vary slightly each time because simulations are random; different runs may give slightly different p-values.
Works with any statistic (means, medians, proportions, etc.), not just means.Requires technology — hard to do 1,000+ shuffles by hand.
No assumptions about the shape of the population (like normality).With very small sample sizes, the number of possible shuffles is limited, which can make p-value estimates coarse.
Great for building understanding before learning formal tests.Does not tell you how big the effect is — only whether it's unlikely to be zero.
KEY TAKEAWAY
Simulation is like using a flight simulator before flying a real plane. It gives you hands-on experience with the concept of statistical significance — seeing how variability behaves — before you encounter the formal mathematical machinery (z-tests, t-tests, chi-squared tests) that automates the same idea with formulas.

Connection to Formal Hypothesis Testing

Simulation-based inference and traditional hypothesis tests (like the two-sample t-test) answer the same question — is the observed difference explainable by chance? — but they get there differently. As you move into more advanced statistics courses, you'll see how formulas can replace shuffling, especially when sample sizes are large and certain conditions are met.

Simulation vs. traditional two-sample t-test
FeatureSimulation TestTwo-Sample t-Test
How it builds the null distributionPhysically shuffles data and records simulated differencesUses a mathematical formula (the t-distribution) to model what chance looks like
AssumptionsMinimal — no requirement that data be normally distributedAssumes roughly normal populations or large enough samples (Central Limit Theorem)
Technology neededYes — need to run many shufflesCalculator or table lookup is sufficient
Precision of p-valueApproximate — depends on number of simulationsExact (given assumptions are met)
Best forBuilding intuition; small or non-normal data setsQuick, precise inference when conditions are satisfied

The beautiful takeaway is that both approaches typically converge on the same conclusion. In AP Statistics and college-level courses, you will learn the formulas that let you skip the shuffling — but the logic underneath is identical. Understanding simulation first gives you a concrete mental picture of what those formulas are actually computing.

Practice Problems

PROBLEM 1CONCEPTUAL
Explain in your own words why we shuffle the group labels when performing a simulation test. What assumption does this shuffling represent?
PROBLEM 2BASIC CALCULATION
A simulation of 500 shuffles produced the following results: 12 shuffles had a simulated difference ≥ 7.5 in absolute value. The observed difference is 7.5. Calculate the estimated p-value and state whether the result is significant at the 0.05 level.
PROBLEM 3INTERMEDIATE
Group X has values {14, 18, 20, 22} and Group Y has values {10, 12, 16, 14}. (a) Calculate the observed difference in means (Group X − Group Y). (b) One random shuffle assigns {14, 12, 20, 14} to Group X and {10, 18, 16, 22} to Group Y. What is the simulated difference for this shuffle? (c) If 38 out of 1,000 total shuffles produced |D_sim| ≥ your D_obs, what is the estimated p-value?
PROBLEM 4APPLIED
A fitness app company tests two workout routines. After 8 weeks, the "HIIT" group (n = 15) lost an average of 4.8 kg, while the "Steady-State" group (n = 15) lost an average of 3.2 kg. A simulation of 2,000 shuffles produced 87 cases where |D_sim| ≥ 1.6. (a) State the null and alternative hypotheses. (b) Calculate the p-value. (c) At the 0.05 significance level, what should the company conclude? (d) Suggest one reason the company should be cautious about this conclusion.
PROBLEM 5CRITICAL THINKING
Two students each run a simulation test on the same data set. Student A uses 200 shuffles and gets a p-value of 0.045. Student B uses 10,000 shuffles and gets a p-value of 0.062. (a) Explain why their p-values differ. (b) Whose p-value is more trustworthy, and why? (c) Given these conflicting results, what would you recommend before drawing a final conclusion?

Lesson Summary

When you compare two groups, the observed difference alone doesn't tell you whether the gap is real or just random noise. To decide, you assume the null hypothesis (no real difference), shuffle the group labels hundreds or thousands of times, and build a simulated distribution of differences that could arise from chance alone. If your observed difference lands far in the tail of that distribution — captured by a small p-value — you have evidence that the difference is statistically significant.

Remember that statistical significance tells you the difference is unlikely to be zero — it does not guarantee the difference is large or practically important. Always pair your simulation result with context: sample size, effect size, and domain knowledge. This simulation approach mirrors the logic of formal tests like the two-sample t-test, which you will encounter in more advanced courses, but it builds intuition first by letting you see what random variability actually looks like.

Varsity Tutors • Math 3 • Comparing Groups via Simulation