ANOVA¶
Analysis of Variance models
Examples¶
In [1]: import statsmodels.api as sm
ImportErrorTraceback (most recent call last)
<ipython-input-1-6030a6549dc0> in <module>()
----> 1 import statsmodels.api as sm
/builddir/build/BUILD/statsmodels-0.8.0/statsmodels/api.py in <module>()
5 from . import regression
6 from .regression.linear_model import OLS, GLS, WLS, GLSAR
----> 7 from .regression.recursive_ls import RecursiveLS
8 from .regression.quantile_regression import QuantReg
9 from .regression.mixed_linear_model import MixedLM
/builddir/build/BUILD/statsmodels-0.8.0/statsmodels/regression/recursive_ls.py in <module>()
14 from statsmodels.regression.linear_model import OLS
15 from statsmodels.tools.data import _is_using_pandas
---> 16 from statsmodels.tsa.statespace.mlemodel import (
17 MLEModel, MLEResults, MLEResultsWrapper)
18 from statsmodels.tools.tools import Bunch
/builddir/build/BUILD/statsmodels-0.8.0/statsmodels/tsa/statespace/mlemodel.py in <module>()
12 from scipy.stats import norm
13
---> 14 from .kalman_smoother import KalmanSmoother, SmootherResults
15 from .kalman_filter import (KalmanFilter, FilterResults, INVERT_UNIVARIATE,
16 SOLVE_LU)
/builddir/build/BUILD/statsmodels-0.8.0/statsmodels/tsa/statespace/kalman_smoother.py in <module>()
12 import numpy as np
13
---> 14 from statsmodels.tsa.statespace.representation import OptionWrapper
15 from statsmodels.tsa.statespace.kalman_filter import (KalmanFilter,
16 FilterResults)
/builddir/build/BUILD/statsmodels-0.8.0/statsmodels/tsa/statespace/representation.py in <module>()
8
9 import numpy as np
---> 10 from .tools import (
11 find_best_blas_type, prefix_dtype_map, prefix_statespace_map,
12 validate_matrix_shape, validate_vector_shape
/builddir/build/BUILD/statsmodels-0.8.0/statsmodels/tsa/statespace/tools.py in <module>()
10 from scipy.linalg import solve_sylvester
11 from statsmodels.tools.data import _is_using_pandas
---> 12 from . import _statespace
13
14 has_find_best_blas_type = True
ImportError: cannot import name _statespace
In [2]: from statsmodels.formula.api import ols
In [3]: moore = sm.datasets.get_rdataset("Moore", "car",
...: cache=True) # load data
...:
NameErrorTraceback (most recent call last)
<ipython-input-3-924d52d36060> in <module>()
----> 1 moore = sm.datasets.get_rdataset("Moore", "car",
2 cache=True) # load data
NameError: name 'sm' is not defined
In [4]: data = moore.data
NameErrorTraceback (most recent call last)
<ipython-input-4-07b15baaa84d> in <module>()
----> 1 data = moore.data
NameError: name 'moore' is not defined
In [5]: data = data.rename(columns={"partner.status":
...: "partner_status"}) # make name pythonic
...:
NameErrorTraceback (most recent call last)
<ipython-input-5-76a0688779cd> in <module>()
----> 1 data = data.rename(columns={"partner.status":
2 "partner_status"}) # make name pythonic
3
NameError: name 'data' is not defined
In [6]: moore_lm = ols('conformity ~ C(fcategory, Sum)*C(partner_status, Sum)',
...: data=data).fit()
...:
NameErrorTraceback (most recent call last)
<ipython-input-6-0a291eef3047> in <module>()
1 moore_lm = ols('conformity ~ C(fcategory, Sum)*C(partner_status, Sum)',
----> 2 data=data).fit()
NameError: name 'data' is not defined
In [7]: table = sm.stats.anova_lm(moore_lm, typ=2) # Type 2 ANOVA DataFrame
NameErrorTraceback (most recent call last)
<ipython-input-7-4e32df33effd> in <module>()
----> 1 table = sm.stats.anova_lm(moore_lm, typ=2) # Type 2 ANOVA DataFrame
NameError: name 'sm' is not defined
In [8]: print(table)
NameErrorTraceback (most recent call last)
<ipython-input-8-d1f157ed9e2f> in <module>()
----> 1 print(table)
NameError: name 'table' is not defined
A more detailed example can be found here: