ANOVA test (coursera)

This is the code I used

import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols

datafile = "PlantGrowth.csv"
data = pd.read_csv(datafile)

# Create a boxplot
data.boxplot('weight', by='group', figsize=(12, 8))

ctrl = data['weight'][data.group == 'ctrl']

grps = pd.unique(data.group.values)
d_data = {grp: data['weight'][data.group == grp] for grp in grps}

k = len(pd.unique(data.group)) # number of conditions
N = len(data.values) # conditions times participants
n = data.groupby('group').size()[0] # Participants in each condition

mod = ols('weight ~ group', data=data).fit()

aov_table = sm.stats.anova_lm(mod, typ=2)
print(aov_table)

To get the results I wanted, I used statsmodels library as it was shown in course itself. I also made a boxplot to visualise the group’s means, medians and so on.

Judging by the Boxplot there are differences in the dried weight for the two treatments. However, easy to visually determine whether the treatments are different to the control group.

That is the result we got

As we see p value is less that 0.05 , that’s why we reject the Ho hypothesis of equality between groups means.