08-Data Science-S25-Comparing Two Samples
08-Data Science-S25-Comparing Two Samples
Ch. 12
Many slides are created by John DeNero ([email protected]) and Ani Adhikari ([email protected])
Comparing Two Samples
● Compare values of sampled individuals in Group A with
values of sampled individuals in Group B.
(Demo)
Hypotheses
● Null:
○ In the population, the distributions of the birth
weights of the babies in the two groups are the
same. (They are different in the sample just due to
chance.)
● Alternative:
○ In the population, the babies of the mothers who
smoked weigh less, on average, than the babies of
the non-smokers.
Test Statistic
● Group A: non-smokers
● Group B: smokers
...
...
Potential Potential
Outcome Outcome
Outcome if assigned to
control group
Outcome if assigned to
treatment group
The Hypotheses
● Null:
○ In the population, the distribution of all potential
control scores is the same as the distribution of all
potential treatment scores.
○ tl;dr the treatment has no effect
● Alternative:
○ In the population, more of the potential treatment
scores are 1 (pain improves) than the potential
control scores. (Demo)
Random Assignment & Shuffling
Data Sample Hypothesis Testing Conclusions
Generation Data Difference of Means
Permutation Test
Observational
Sample Association
Our Two-
Shuffle Labels
Sample
to Simulate
Numerical Data
from Null
Randomized
Control
Experiment Causation
P-Values and Error Probabilities
Discussion Question
There are 2000 students in a course. Each has a coin to test:
Null: The coin is fair
Alternative: The coin is unfair
● based on 1,000 tosses of a coin,
● the statistic = | number of heads - 500 |,
● and the 5% cutoff for the P-value.
Suppose all 1000 coins are fair. About how many students
will conclude that their coins are unfair?
Statistic Simulated Under the Null
About 5% of the
area is to the right
of the gold line
Can the Conclusion be Wrong?
Yes.
Null is true Alternative is
true
Test favors the
null ✅ ❌
Test favors the
alternative ❌ ✅
An Error Probability
● The cutoff for the P-value is an error probability.
● If:
○ your cutoff is 5%
○ and the null hypothesis happens to be true
(Demo)
Changing number of simulations
Difference from the null
Hypothesis Test Effects
Number of simulations: Make it as large as possible so
that the empirical distribution of the test statistic under the
null distribution is good. No new data needs to be collected.
Number of observations: A larger sample will lead you to
reject the null more reliably if the alternative is in fact true.
Difference from the null: If the null hypothesis is false, but
the truth is similar to the null hypothesis, then even a large
sample may not provide enough evidence to reject the null.