#!/usr/bin/env python # coding: utf-8 # # Two-way ANOVA # ANOVA with interaction: # # *Measurement of fetal head circumference, by four observers in three fetuses, from a study investigating the # reproducibility of ultrasonic fetal head circumference data.* # # Author: Thomas Haslwanter, Date: June-2014 # In[3]: get_ipython().run_line_magic('pylab', 'inline') import pandas as pd import urllib from statsmodels.formula.api import ols from statsmodels.stats.anova import anova_lm # ## Get and format the data # In[4]: inFile = 'altman_12_6.txt' url_base = 'https://raw.githubusercontent.com/thomas-haslwanter/statsintro_python/master/ipynb/Data/data_altman/' url = url_base + inFile data = genfromtxt(urllib.request.urlopen(url), delimiter=',') # Bring them in dataframe-format df = pd.DataFrame(data, columns=['hs', 'fetus', 'observer']) # ## ANOVA with interaction # In[5]: formula = 'hs ~ C(fetus) + C(observer) + C(fetus):C(observer)' lm = ols(formula, df).fit() print(anova_lm(lm))