ANOVA
Analysis of Variance models containing anova_lm for ANOVA analysis with a linear OLSModel, and AnovaRM for repeated measures ANOVA, within ANOVA for balanced data.
Examples
In [1]: import statsmodels.api as sm In [2]: from statsmodels.formula.api import ols In [3]: moore = sm.datasets.get_rdataset("Moore", "car", ...: cache=True) # load data ...: In [4]: data = moore.data In [5]: data = data.rename(columns={"partner.status": ...: "partner_status"}) # make name pythonic ...: In [6]: moore_lm = ols('conformity ~ C(fcategory, Sum)*C(partner_status, Sum)', ...: data=data).fit() ...: In [7]: table = sm.stats.anova_lm(moore_lm, typ=2) # Type 2 ANOVA DataFrame In [8]: print(table) sum_sq df F \ C(fcategory, Sum) 11.614700 2.0 0.276958 C(partner_status, Sum) 212.213778 1.0 10.120692 C(fcategory, Sum):C(partner_status, Sum) 175.488928 2.0 4.184623 Residual 817.763961 39.0 NaN PR(>F) C(fcategory, Sum) 0.759564 C(partner_status, Sum) 0.002874 C(fcategory, Sum):C(partner_status, Sum) 0.022572 Residual NaN
A more detailed example for anova_lm
can be found here:
Module Reference
anova_lm (*args, **kwargs) | Anova table for one or more fitted linear models. |
AnovaRM (data, depvar, subject[, within, …]) | Repeated measures Anova using least squares regression |
© 2009–2012 Statsmodels Developers
© 2006–2008 Scipy Developers
© 2006 Jonathan E. Taylor
Licensed under the 3-clause BSD License.
http://www.statsmodels.org/stable/anova.html