Repository navigation
REF: Move method of IV2SLS and IVLIML from the model to fit - #873
Merged
Merged
Conversation
The numerical method is a property of an estimate, not of the model, so it is passed to fit and stored on the results, which use it for their diagnostics. The model no longer stores a method, so one model can be fit with both. The rank check of each method stays in the model, keyed by the method: the model is rejected when neither method can estimate it, and fit raises the error of the method it is given. method was added in 7.2 and has not been released.
The results of IV2SLS and IVLIML report the method of fit as the public property numerical_method. The results of IVGMM, IVGMMCUE and IVJIVE report "pinv". The name method is taken by the estimator name, such as "IV-2SLS".
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #873 +/- ##
=======================================
Coverage 99.69% 99.69%
=======================================
Files 202 202
Lines 38797 38876 +79
Branches 2497 2502 +5
=======================================
+ Hits 38677 38756 +79
Misses 51 51
Partials 69 69
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:
|
…n fit The rank tests of both methods now come from one QR decomposition of the weighted regressors and instruments, which the estimates use. 7.1 tested the unweighted ones, whose condition number can differ greatly from that of the weighted ones. The singular values of R give the test of "pinv", and those of R with columns scaled by the column norms give the test of "qr". The model keeps the orthonormal basis of the weighted instruments, and fit with method="qr" uses it for the estimate, the covariance and kappa, whose basis of the exogenous regressors is its first columns. A qr fit no longer decomposes the data.
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.
The numerical method of
IV2SLSandIVLIML(#870) is a property of an estimate, not of the model. This movesmethodfrom the constructors andfrom_formulatofit.methodwas added in 7.2 and has not been released, so there is no deprecation.fit(method=...)validates the method and warns if it is not given, as the constructors did. TheFutureWarningnow comes fromfit.fit_method("pinv" forIVGMM,IVGMMCUEandIVJIVE;methodis already the estimator name, such as "IV-2SLS"), and their diagnostics use it: the first stage, Sargan, Durbin, Wu-Hausman and the Wooldridge tests. The model no longer stores a method, so one model can be fit with both methods without one fit affecting the next._rank_errors, keyed by method). The model is rejected when it is built only if neither method can estimate it, with the 7.1 message. Otherwisefitraises the error of the method it is given. For example, columns that are rank deficient only because of their units now build, andfit(method="pinv")raises with the hint that"qr"accepts them."pinv", and those of R with columns scaled by the column norms give the test of"qr". Building the model costs about the same as on main.test_weights_finiteexpects that.fit(method="qr")uses it for the estimate, the covariance and the LIML kappa, whose basis of the exogenous regressors is its first columns, so a qr fit does not decompose the data. At n = 1M with 15 instruments a qr fit takes 0.80 s instead of 1.24 s, and at n = 100k with 150 instruments 0.47 s instead of 3.21 s. The cost is an array the size of the instruments kept on the model.IVGMM,IVGMMCUEandIVJIVEdo not keep it and use"pinv".methodtofit.Tests: the fast suite passes locally (23,387 passed). The notebooks run without warnings, and every added line and branch is covered. A new test fits the same model with
"qr", then"pinv", and checks each result and its diagnostics against a fit of a fresh model.🤖 Generated with Claude Code