| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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 98.49624% with 2 lines in your changes missing coverage. Please review.
@@ 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.
|
Sorry, something went wrong.
There was a problem hiding this comment.
Please fix the ruff linting error.
Sorry, something went wrong.
|
Need Ruff fix, and probably to be blackened. Should probably run isort on the changed files as well. Oh no! 💥 💔 💥
5 files would be reformatted, 124 files would be left unchanged.
Skipped 1 files
RUF002 Docstring contains ambiguous `–` (EN DASH). Did you mean `-` (HYPHEN-MINUS)?
--> linearmodels/iv/model.py:1098:54
|
1096 | ----------
1097 | Hansen, B. E. & Lee, S. (2021). Inference for iterated GMM under
1098 | misspecification. *Econometrica*, 89(3), 1419–1447.
| ^
1099 | """
1100 | y, x, z = self._wy, self._wx, self._wz
|
RUF002 Docstring contains ambiguous `–` (EN DASH). Did you mean `-` (HYPHEN-MINUS)?
--> linearmodels/iv/results.py:1503:54
|
1501 | ----------
1502 | Hansen, B. E. & Lee, S. (2021). Inference for iterated GMM under
1503 | misspecification. *Econometrica*, 89(3), 1419–1447.
| ^
1504 | """
1505 | return self._robust_j_stat
|
F841 Local variable `expected_df` is assigned to but never used
--> linearmodels/tests/iv/test_hansen_lee_j_stat.py:78:5
|
76 | ninstr = data.instr.shape[1] + data.exog.shape[1]
77 | nendog = data.endog.shape[1]
78 | expected_df = ninstr - nendog - data.exog.shape[1]
| ^^^^^^^^^^^
79 | # df = total instruments - total params = (nexog+ninstr) - (nexog+nendog)
80 | # = ninstr - nendog
|
help: Remove assignment to unused variable `expected_df`
Found 3 errors.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
linearmodels/tests/iv/test_hansen_lee_j_stat.py:78:5: F841 local variable 'expected_df' is assigned to but never used
|
Sorry, something went wrong.
| 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] |
| Back | FazBrowse Home | New Git URL |
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.