Repository navigation
BUG: Test the rank of the IV inputs after scaling the columns - #850
Open
inchang-ing wants to merge 1 commit into
Open
inchang-ing wants to merge 1 commit into
inchang-ing wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #850 +/- ##
=======================================
Coverage 99.68% 99.68%
=======================================
Files 199 199
Lines 37851 37861 +10
Branches 2433 2433
=======================================
+ Hits 37730 37742 +12
+ Misses 53 51 -2
Partials 68 68
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:
|
Contributor
Author
|
Gentle ping on this one — CI is green (15/15) and it is a small, self-contained bug fix. Would appreciate a review when you get a chance. Thanks! |
Owner
|
I'm not a fan of this. the regression is in the scale of the original columns, and if they are poorly scaled the numerics of the regression may be problematic. A rank check in the same scale as the regression should help protect the user from these numeric problems. What do you think? |
This branch has not been deployed
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.
Addresses case 3 of #823.
The rank checks in
_validate_inputscallmatrix_rankon the raw regressor and instrument matrices.matrix_rankthresholds the singular values relative to the largest one, so columns on very different scales look rank deficient even when they are not:Change
Both rank checks now scale the columns to unit length first, so the result does not depend on the units of the variables. A column that is exactly 0 cannot be scaled and is still detected as linearly dependent.
This is only the third case of #823; the LIML kappa cases (1 and 2) are untouched, since they need the relative-residual test and the joint change to the scaling of kappa.
Tests
test_instr_rank_check_is_scale_invariantintests/iv/test_model.py; it fits the model with an instrument scaled by1e13and compares the estimates with the unscaled ones.linearmodels/tests/iv/: 9522 passed, 2400 skipped.ruff checkandnumpydoc lintpass on the changed files.