Chapter 1
Chapter 1
z-scores
HYPOTHESIS TESTING IN PYTHON
James Chapman
Curriculum Manager, DataCamp
A/B testing
In 2013, Electronic Arts (EA) released
SimCity 5
mean_comp_samp = stack_overflow['converted_comp'].mean()
119574.71738168952
5607.997577378606
119574.71738168952
mean_comp_hyp = 110000
std_error
5607.997577378606
1.7073326529796957
Determine whether sample statistics are close to or far away from expected (or
"hypothesized" values)
James Chapman
Curriculum Manager, DataCamp
Criminal trials
Two possible true states:
1. Defendant committed the crime
2. Not guilty
Prosecution must present evidence "beyond reasonable doubt" for a guilty verdict
The alternative hypothesis (HA ) is the new "challenger" idea of the researcher
1"Naught" is British English for "zero". For historical reasons, "H-naught" is the international convention for
pronouncing the null hypothesis.
If the evidence from the sample is "significant" that HA is true, reject H0 , else choose H0
Test Tails
alternative different from null two-tailed
alternative greater than null right-tailed
alternative less than null left-tailed
0.39141972578505085
prop_child_hyp = 0.35
0.010351057228878566
4.001497129152506
3.1471479512323874e-05
James Chapman
Curriculum Manager, DataCamp
p-value recap
p-values quantify evidence for the null hypothesis
Large p-value → fail to reject null hypothesis
3.1471479512323874e-05
3.1471479512323874e-05
True
Reject H0 in favor of HA
import numpy as np
lower = np.quantile(first_code_boot_distn, 0.025)
upper = np.quantile(first_code_boot_distn, 0.975)
print((lower, upper))
(0.37063246351172047, 0.41132242370632466)
actual H0 actual HA
False positives are Type I errors; false negatives are Type II errors.
A false positive (Type I) error: data scientists didn't start coding as children at a higher rate
A false negative (Type II) error: data scientists started coding as children at a higher rate