Skip to content

ANOVA for GLM #825

Open
Open

Description

@thomas-haslwanter

anova_lm is NOT supported by GLM
e.g. glm_model = sm.GLM.from_formula('weight~group', family=sm.families.Gaussian(), data=df).fit()

but is supported by OLS
e.g. model = sm.OLS.from_formula('weight~group', data=df).fit()

It would be nice (and more consistent with R) if it were possible to define the ANOVA such that both models are supported (perhaps by using the deviance instead of ssr).

If there are no changes in the implementation, at least the docu of anova_lm should mention that it only works for OLS, not for GLM.

Activity

  1. added this to the 0.7 milestone on Dec 6, 2014
  2. josef-pkt commented on Dec 6, 2014

    @josef-pkt
    Member

    another request for it anova_glm http://stackoverflow.com/questions/27328623/anova-test-for-glm-in-python

    update

    this now has an answer with something like a compare_deviance_test
    IIRC, I have similar comparisons in my loglinear model notebook, also one based on pearson chi2

    from scipy import stats
    
    def calculate_nested_f_statistic(small_model, big_model):
        """Given two fitted GLMs, the larger of which contains the parameter space of the smaller, return the F Stat and P value corresponding to the larger model adding explanatory power"""
        addtl_params = big_model.df_model - small_model.df_model
        f_stat = (small_model.deviance - big_model.deviance) / (addtl_params * big_model.scale)
        df_numerator = addtl_params
        # use fitted values to obtain n_obs from model object:
        df_denom = (big_model.fittedvalues.shape[0] - big_model.df_model)
        p_value = stats.f.sf(f_stat, df_numerator, df_denom)
        return (f_stat, p_value)
    
  3. jseabold commented on Jan 19, 2015

    @jseabold
    Member

    FWIW, IIRC this should be something like a 6 line change in anova_lm code. Just use the deviance residuals and a different distribution.

  4. modified the milestones: 0.8, 0.7 on Jul 17, 2015
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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions