Types of ANOVA
- There are 3 main types of ANOVA, depending on the number of independent variables and interactions involved:
One-Way ANOVA also ttest two sample
What it compares: One independent variable (factor) with 2 or more groups.
Example: Comparing test scores between 3 teaching methods.
Assumption: Groups are independent and data is normally distributed.
Python function: scipy.stats.f_oneway()
from scipy.stats import f_oneway
import numpy as np
campaign_A = [12, 15, 14, 10, 13, 15, 11, 14, 13, 16]
campaign_B = [18, 17, 16, 15, 20, 19, 18, 16, 17, 19]
campaign_C = [10, 9, 11, 10, 12, 9, 11, 8, 10, 9]
f_stats, p_value = f_oneway(campaign_A,campaign_B,campaign_C)
print(f_stats, p_value)
alpha = 0.05
if p_value < alpha:
print ("reject the null hypothesis")
else:
print ("fail to reject null hypothesis")
Two-Way ANOVA
What it compares: Two independent variables, possibly with interaction.
Example: Test scores by teaching method and gender (2 factors).
You can also test: Interaction effect — whether the effect of one factor depends on the other.
📍 Usually implemented using statsmodels with a formula:
from statsmodels.formula.api import ols
import statsmodels.api as sm
model = ols('Score ~ C(Method) + C(Gender) + C(Method):C(Gender)', data=df).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
Repeated Measures ANOVA
What it compares: Same subjects measured under different conditions or times.
Example: Blood pressure before, during, and after treatment on same patients.
Use when: Data is not independent, i.e., repeated measures from same subjects.
Python: statsmodels or pingouin library.
Top comments (0)