Repository navigation
Closed
Labels
Milestone
Description
I'm not sure what's going on with the df in wald_test_terms results
I'm working with a GAM example in a notebook, and the df in the results is equal to the number of coefficients and not 1 as it should be for a single constraint.
The constraint matrix (returned in temp) are 1-D for single column constraints and not 2-D as for joint hypothesis. So there might be a incorrect df = constraint.shape[0] or missing atleast_2d.
Why doesn't this show up in the unit tests?
res_bsf.wald_test_terms(skip_single=False, combine_terms=['fuel', 'drive', 'weight', 'hp'])
<class 'statsmodels.stats.contrast.WaldTestResults'>
chi2 P>chi2 df constraint
Intercept 677.786660 2.024193e-149 24
fuel[T.gas] 63.823523 1.360790e-15 24
drive[T.fwd] 2.887571 8.926542e-02 24
drive[T.rwd] 1.594575 2.066736e-01 24
weight_s0 13.741523 2.097653e-04 24
weight_s1 26.966268 2.070372e-07 24
weight_s2 50.869767 9.870223e-13 24
weight_s3 59.216023 1.412788e-14 24
weight_s4 64.379100 1.026412e-15 24
weight_s5 66.065909 4.360938e-16 24
weight_s6 66.597275 3.330462e-16 24
weight_s7 69.019581 9.749068e-17 24
weight_s8 66.816994 2.979188e-16 24
weight_s9 71.769472 2.418654e-17 24
weight_s10 72.534338 1.641508e-17 24
hp_s0 6.717964 9.544654e-03 24
hp_s1 11.429164 7.230019e-04 24
hp_s2 22.246778 2.397608e-06 24
hp_s3 28.663073 8.613056e-08 24
hp_s4 43.307451 4.677986e-11 24
hp_s5 42.858347 5.885046e-11 24
hp_s6 35.971865 2.001873e-09 24
hp_s7 18.913675 1.367687e-05 24
hp_s8 21.947246 2.802488e-06 24
fuel 63.823523 1.360790e-15 1
drive 2.982567 2.250835e-01 2
weight 97.733732 5.013118e-16 11
hp 74.837143 1.701728e-12 9
Activity
josef-pkt commentedon Jan 19, 2019
Needs investigating to see whether this is the case in general or whether there is something specific to my model. (There should not be anything specific to GAM and my GAM example for this.)
josef-pkt commentedon Jan 19, 2019
confirmed bug in results table for wald_test_terms
I'm using
constraint.shape[0]for df_constraint instead of the value that wald_test returns.The p-values are correct and the correct test is used because wald_test handles 1-D constraint correctly.
But the returned df_constraint is wrong if constraint is 1-D.
unit tests in base test_generic_methods
compare_waldreschecks the df and usesdf = c.shape[0] if c.ndim == 2 else 1However, AFAICS there is no test class with a single column variable, i.e. with single, simple constraint.
josef-pkt commentedon Jan 19, 2019
names for df
I don't like df_num, df_denom because I never remember what they are and which is which
it looks like
chi2hasdf_constraintsindf_denom, andFhas it indf_numwald_test_termsusesdf_constraintsand additionallydf_denomin case of Fwald_test_terms does not have a
use_foption.so, cheating
josef-pkt commentedon Jan 19, 2019
quickfix for
wald_test_terms: make simple constraint matrix into 2-D array (one 2-D row)cleaner version:
unify and add/rename
df_constraintsin wald_test, reuse df_constraint for wald_test_terms return table.josef-pkt commentedon Jan 29, 2019
I was using this uncommitted change in the GAM PR #5370 (I will not include it there. PR not recently rebased)
This worked fine in my examples, but there are no unit tests yet.
josef-pkt commentedon May 9, 2019
simple example with problem using GLM with data from gam tests
wrong in model created with pandas data
model created with formulas shows correct df
josef-pkt commentedon May 9, 2019
In the formula path of wald_test_terms all constraint matrices are 2-dim,
so adding
atleast_2dto the non-formula path makes this the samefrom
vars(wtf)BUG: fix df in summary for single constraint in wald_test_terms closes …
BUG: fix df in summary for single constraint in wald_test_terms closes …