ENH: Add no cross terms option to White's test for heteroscedasticity#9691
ENH: Add no cross terms option to White's test for heteroscedasticity#9691IntegralIndefinida wants to merge 7 commits intostatsmodels:mainfrom
Conversation
|
|
||
| hw = smdia.het_white(res.resid, res.model.exog,cross_terms=False) | ||
| hw_values = ( | ||
| 13.25091965953952 |
There was a problem hiding this comment.
commas are missing at end of lines
statsmodels/stats/diagnostic.py
Outdated
|
|
||
|
|
||
| def het_white(resid, exog): | ||
| def het_white(resid, exog,cross_terms=True): |
statsmodels/stats/diagnostic.py
Outdated
| exog : array_like | ||
| The explanatory variables for the variance. Squares and interaction | ||
| terms are automatically included in the auxiliary regression. | ||
| The explanatory variables for the variance. Squares terms are automatically |
There was a problem hiding this comment.
keep closer to original just add "by default":
Squares and, by default, interaction terms are automatically included in the auxiliary regression.
|
Looks good overall I guess this will then be equivalent to So, not really needed but addition is fine with me. |
c9df30d to
9855622
Compare
9855622 to
43be2d3
Compare
|
Thank you for your comments. I also changed the flag to |
|
Thanks, |
|
ci fails and one style failure with white space |
statsmodels/stats/diagnostic.py
Outdated
| i0, i1 = np.triu_indices(nvars0) | ||
| exog = x[:, i0] * x[:, i1] | ||
| nobs, nvars = exog.shape | ||
| assert nvars == nvars0 * (nvars0 - 1) / 2. + nvars0 |
There was a problem hiding this comment.
It was in the original function, should I remove it anyway?
| terms are automatically included in the auxiliary regression. | ||
| The explanatory variables for the variance. Squares and, by default, | ||
| interaction terms are automatically included in the auxiliary regression. | ||
| interaction_terms : bool, default True |
There was a problem hiding this comment.
Should probably be False for now since this would change the output of tests without a deprecation.
There was a problem hiding this comment.
interaction_term = True
is the current behavior and needed for backwards compatibility and is the "proper" White test
There was a problem hiding this comment.
Sorry - read title backward. Yes, True by default.
sorry, I'll fix that |
|
Really should add a check that |
That's done by |
|
I also removed the line because, as @bashtage says, a constant term is required and the F-statistic indeed makes sense, since the White's test only distributes |
bashtage
left a comment
There was a problem hiding this comment.
One small change to improve doc generation.
statsmodels/stats/diagnostic.py
Outdated
|
|
||
| References | ||
| ---------- | ||
| Greene section 11.4.1 5th edition p. 222. Test statistic reproduces |
There was a problem hiding this comment.
Could we change the references to have the propper format. Should be like
.. [1] Greene, William H. Econometric analysis. 5th Edition. Pearson Education, 2002.
.. [2] Damodar N. Gujarati, Basic Econometrics, section 11.5. Pg 387.
There was a problem hiding this comment.
Sure, that'd be better
|
Close and reopen to force CI run |
|
statsmodels/stats/diagnostic.py:827:1: E302 expected 2 blank lines, found 1 Lint failure |
|
I fixed the missing line, but the test still fails with the following linting errors: Those are unrelated to my commits |
|
Closing and reopening to see CI run |
This PR adds a
interaction_termsparameter to thehet_whitefunction to allow users to choose whether to include interaction terms in White's heteroskedasticity test. This is useful since adding the cross terms consumes degrees of freedom. Additionally, White's heteroscedasticity test with cross terms can also be a specification test, and, according to Richard Harris (as cited in Gujarati's chapter on heteroscedasticity), if we remove the cross terms, it constitutes a pure heteroscedasticity test.Changes
interaction_termsparameter (defaultTrue) tostatsmodels.stats.diagnostic.het_whiteinteraction_terms=False, the test uses only squared terms (x1², x2², ...) without interaction terms (x1x2, x1x3, ...)Tests
Added
test_het_white_no_interaction_termsto verify theinteraction_terms=FalseoptionReference values verified against EViews (I also verified the base variant results)
[ x ] tests added / passed.
[ x ] code/documentation is well formatted.
[ x ] properly formatted commit message. See
NumPy's guide.
Details
Notes:
needed for doc changes.
then show that it is fixed with the new code.
verify you changes are well formatted by running
flake8is installed. This command is also available on Windowsusing the Windows System for Linux once
flake8is installed in thelocal Linux environment. While passing this test is not required, it is good practice and it help
improve code quality in
statsmodels.