ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
1 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
2 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
3 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
4 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
5 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
6 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
from scipy import stats
import pandas as pd
# import the data
df= pd.read_csv("Iris_Data.csv")
setosa = df[(df['species'] == 'Iris-setosa')]
versicolor = df[(df['species'] == 'Iris-versicolor')]
# homogeneity
stats.levene(setosa['sepal_width'],
versicolor['sepal_width'])
# Shapiro-Wilk test for normality
stats.shapiro(setosa['sepal_width'])
stats.shapiro(versicolor['sepal_width'])
stats.ttest_ind(setosa['sepal_width'],
7 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
versicolor['sepal_width'])
import pingouin as pg
# Read an example dataset
df = pg.read_dataset('mixed_anova')
# Run the ANOVA
aov = pg.anova(data=df, dv='Scores', between='Group',
detailed=True)
print(aov)
8 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
pg.rm_anova(data=df, dv='Scores', within='Time',
subject='Subject', detailed=True)
from statsmodels.multivariate.manova import MANOVA
maov = MANOVA.from_formula('Sepal_Length + Sepal_Width + \
Petal_Length + Petal_Width ~
Species', data=df)
print(maov.mv_test())
9 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
10 of 11 9/30/2021, 12:32 PM
ANOVA, T-test and other statistical tests with Python | by Fra... https://towardsdatascience.com/anova-t-test-and-other-statistic...
11 of 11 9/30/2021, 12:32 PM