Professional Documents
Culture Documents
Testing in Python
T-Test, ANOVA, Chi-Squared Test with Examples
T-Test
ANOVA Test
ANOVA Test (image by author)
Now that we know t-test is used to compare the mean of one or two
sample groups. What if we want to test more than two samples?
Use ANOVA test.
dfn = n — 1
dfd = n — k
from scipy.stats import f
dfn = 3-1
dfd = 100-3
rv = f(dfn, dfd)
To easily get the f-statistics and p-value using Python, we can use
the function stats.f_oneway() which returns p-value: 0.00040.
f_stat, pvalue = stats.f_oneway(kidhome_0, kidhome_1,
kidhome_2)
1. define hypothesis:
Python also provides a useful function to get the chi statistics and
p-value given the contingency table.
chi2_stat, pvalue, dof, exp = chi2_contingency(ed_contingency)
An interactive visualization of chi-distribution with chi-statistics (check
the code)
If you would like to read more articles like this, I would really
appreciate your support by signing up Medium membership :)
Take-Home Message