Skip to content

Ordering in Type I ANOVA #1112

Open
Open

Description

@carsonfarmer

Trying to compute Type I ANOVA tests on a model:

from statsmodels.stats.anova import anova_lm
import statsmodels.formula.api as sm
import pandas as pd
cps = pd.read_csv("http://www.mosaic-web.org/go/datasets/cps.csv")
mod1 = sm.ols("wage ~ married + age + educ", data=cps)
fit1 = mod1.fit()
anova_lm(fit1, typ=1)

which is working beautifully. However, I'd like to compare this with married (which is a categorical variable) coming in last in the ANOVA test. I had thought that this would do the trick:

mod2 = sm.ols("wage ~ age + educ + married", data=cps)
fit2 = mod2.fit()
anova_lm(fit2, typ=1)

however, patsy always puts the categorical variables first in the design matrix.

Based on a conversation on the mailing list, it looks like the most viable option to control order is to add an order argument to anova_lm (and its 'sub-fuctions').

statsmodels.__version__
'0.5.0'
patsy.__version__
'0.1.0'

Activity

  1. added this to the 0.10 milestone on Apr 3, 2018
  2. josef-pkt commented on Apr 3, 2018

    @josef-pkt
    Member

    I guess this has never been addressed, and I just found it while searching for type 2.

    Needs checking for 0.10, I'm not familiar enough with the implementation details

  3. modified the milestones: 0.10, 0.15 on Nov 9, 2022
  4. josef-pkt commented on Nov 9, 2022

    @josef-pkt
    Member

    I just found this again searching for anova types

    maybe for 0.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions