Performing Experiments in Python
Luke Hayden
Instructor
Data contains patterns
Some expected
Others surprising
Random variation also
Dealing with this
Weights of two groups of adults
Sample A:
[66.1, 69.8,67.7,69.6,71.1]
Sample B:
[83.7,81.5, 80.6, 83.9, 84.4]
(p9.ggplot(df)+
p9.aes('Value', fill='Sample')+
p9.geom_density(alpha=0.5))
Are these different?
Null hypothesis
A = B
Alternative hypothesis
A != B
p-value
alpha
Crucial threshold of p-value
Usually alpha < 0.05: reject null hypothesis
Invented by William Sealy Gosset
Two basic types:
One-sample: Mean of population different from a given value?
Two-sample: Two means equal?
Coding a t-test
from scipy import stats
stats.ttest_ind(Sample_A, Sample_B)
from scipy import stats
Sample_A = df[df.Sample == "A"]
t_result = stats.ttest_1sample(Sample_A, 65)
alpha = 0.05
if (t_result[1] < alpha):
print("mean(A) != 65")
mean(A) != 65
from scipy import stats
Sample_A = df[df.Sample == "A"]
Sample_B = df[df.Sample == "B"]
t_result = stats.ttest_ind(Sample_A, Sample_B)
alpha = 0.05
if (t_result[1] < alpha):
print("A and B are different!")
A and B are different!
Performing Experiments in Python