You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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)
Activity
josef-pkt commentedon May 11, 2013
related compare_lr is currently only in linear model Results
http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.RegressionResults.compare_lr_test.html
my guess is that compare deviance should produce the same results
josef-pkt commentedon Dec 6, 2014
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_testIIRC, I have similar comparisons in my loglinear model notebook, also one based on pearson chi2
jseabold commentedon Jan 19, 2015
FWIW, IIRC this should be something like a 6 line change in
anova_lmcode. Just use the deviance residuals and a different distribution.