-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo way Anova
26 lines (21 loc) · 1.13 KB
/
two way Anova
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#Let us consider an example in which scientists need to know whether plant growth is affected by fertilizers and watering frequency.
#They planted exactly 30 plants and allowed them to grow for six months under different conditions for fertilizers and watering frequency.
#After exactly six months, they recorded the heights of each plant centimeters.
# Importing libraries
import numpy as np
import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols
# Create a dataframe
dataframe = pd.DataFrame({'Fertilizer': np.repeat(['daily', 'weekly'], 15),
'Watering': np.repeat(['daily', 'weekly'], 15),
'height': [14, 16, 15, 15, 16, 13, 12, 11, 14,
15, 16, 16, 17, 18, 14, 13, 14, 14,
14, 15, 16, 16, 17, 18, 14, 13, 14,
14, 14, 15]})
# Performing two-way ANOVA
model = ols('height ~ C(Fertilizer) + C(Watering) +\C(Fertilizer):C(Watering)',
data=dataframe).fit()
result = sm.stats.anova_lm(model, type=2)
# Print the result
print(result)