ENH: Add Hansen-Lee misspecification-robust J-test to IVGMM#701
Open
hass-nation wants to merge 1 commit into
Open
ENH: Add Hansen-Lee misspecification-robust J-test to IVGMM#701hass-nation wants to merge 1 commit into
hass-nation wants to merge 1 commit into
Conversation
Adds `robust_j_stat` property to `IVGMMResults` (and `IVGMMCUE`),
implementing the misspecification-robust J-test from Hansen & Lee
(2021, Econometrica, 89(3), 1419-1447).
The standard J-statistic uses the uncentered moment covariance as its
weight matrix, which under model misspecification (E[g(z,theta)] != 0)
leads to a test that saturates at n rather than diverging. The
Hansen-Lee statistic replaces the uncentered covariance with the
*centered* covariance S_c = (1/n) sum (g_i - g_bar)(g_i - g_bar)',
giving J* = n * g_bar' S_c^{-1} g_bar ~ chi2(q) under correct
specification and diverging at rate n under misspecification.
Changes:
- `_IVGMMBase._hansen_lee_j_statistic`: computes J* for any cov_type
(robust/heteroskedastic, homoskedastic, kernel, clustered)
- `_IVGMMBase._gmm_post_estimation` + `IVGMM._gmm_post_estimation`:
accept cov_type/cov_config and include `robust_j_stat` in results
- `IVGMM.fit` + `IVGMMCUE.fit`: pass cov_type/cov_config through
- `IVGMMResults.robust_j_stat` property with full docstring
- `IVGMMResults._top_right`: summary now shows both J-stats side-by-side
- 14 new tests in `linearmodels/tests/iv/test_hansen_lee_j_stat.py`
covering type checks, formula verification, all cov_types, CUE,
summary display, and the algebraic identity J* = J*n/(n-J) for
iterated GMM
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #701 +/- ##
==========================================
- Coverage 99.54% 99.53% -0.01%
==========================================
Files 101 102 +1
Lines 17426 17557 +131
Branches 1430 1437 +7
==========================================
+ Hits 17347 17476 +129
- Misses 29 30 +1
- Partials 50 51 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bashtage
requested changes
Jun 28, 2026
bashtage
left a comment
Owner
There was a problem hiding this comment.
Please fix the ruff linting error.
Owner
|
Need Ruff fix, and probably to be blackened. Should probably run isort on the changed files as well. |
| def test_robust_j_stat_df_equals_overidentification_degree(res_robust, data): | ||
| ninstr = data.instr.shape[1] + data.exog.shape[1] | ||
| nendog = data.endog.shape[1] | ||
| expected_df = ninstr - nendog - data.exog.shape[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #430
What this adds
IVGMMResults.robust_j_stat— a misspecification-robust J-test from Hansen & Lee (2021, Econometrica 89(3), 1419-1447).The standard J-statistic uses the uncentered moment covariance as its weight matrix. Under misspecification (E[g(z,θ)] != 0), this causes the test to saturate — it stays bounded by n rather than diverging. The robust statistic replaces the uncentered covariance with the centered covariance S_c = (1/n) sum (g_i - g_bar)(g_i - g_bar)' giving J* = n g_bar' S_c^{-1} g_bar ~ chi2(q) under correct specification and diverging at rate n under misspecification.
API
Works for all cov_type values: robust, unadjusted, kernel, clustered.
Implementation
Tests: 14 new, 6515 existing all pass
References
Hansen, B. E. & Lee, S. (2021). Inference for iterated GMM under misspecification. Econometrica, 89(3), 1419-1447.