Repository navigation
Score/LM conditional moment tests - #2096
Conversation
|
There are/were some problems with Coveralls.io (scipy's frontpage also hasn't updated since the same day) |
|
moved to 0.8 |
|
see #2637 (comment) |
josef-pkt
left a comment
There was a problem hiding this comment.
brief superficial skimming
I guess this needs more examples in unit tests.
AFAIR, these functions are not in other packages, but we might be able to test some special cases.
Also, check for larger nobs where hypothesis tests should be equivalent in large samples.
Otherwise, we can check some examples with Monte Carlos.
| return stat, pval, stat2 | ||
|
|
||
|
|
||
| def lm_robust(score, R, Ainv, B, V=None): |
There was a problem hiding this comment.
replace 1 letter names
| return lm_stat#, lm_stat2 | ||
|
|
||
|
|
||
| def lm_robust_subset(score, k_constraints, score_deriv, cov_score): |
There was a problem hiding this comment.
I guess it would be better of k_constraints allows an index as option, instead of assuming sorted by Null hypothesis
| Returns | ||
| ------- | ||
| lm_stat : float | ||
| score/lagrange multiplier statistic |
There was a problem hiding this comment.
does not return a results instance, why not?
| description.append(['CT nb1 HC1', 'mu (1 + a)']) | ||
|
|
||
|
|
||
| return np.array(results_all), description |
There was a problem hiding this comment.
return results instance that is more informative ?
| return lm_stat, pval | ||
|
|
||
|
|
||
| def dispersion_poisson(results): |
There was a problem hiding this comment.
add method argument instead of always computing all of them
| res_ols = OLS(endog_v, ex).fit(cov_type=cov_type, cov_kwds=cov_kwds, | ||
| use_t=use_t) | ||
|
|
||
| if use_wald: |
There was a problem hiding this comment.
is this just internal or a different statistic? no option for this
(I don't remember if these are numerically equivalent procedures)
|
|
||
|
|
||
| class TestCMTOLS(CheckCMT): | ||
|
|
There was a problem hiding this comment.
add code comment to what this is testing
|
Also, by now we should have some special cases for different models which we can use to check/test against. |
|
rebased on master (no merge conflicts) |
|
all green, test coverage drops quite a bit. (main problem with PR: not much in other packages for verifying this) maybe just verify with simple MonteCarlo, and add regression tests One possibility, use zero restriction i.e. added variable tests as special case. |
35c8e77 to
7f1f3dd
Compare
|
rebased again, no merge conflicts |
Codecov Report
@@ Coverage Diff @@
## master #2096 +/- ##
==========================================
+ Coverage 80.72% 80.79% +0.06%
==========================================
Files 573 577 +4
Lines 88061 88740 +679
Branches 9906 9945 +39
==========================================
+ Hits 71087 71696 +609
- Misses 14696 14747 +51
- Partials 2278 2297 +19
Continue to review full report at Codecov.
|
|
This pull request introduces 3 alerts - view on lgtm.com new alerts:
Comment posted by lgtm.com |
coded directly from articles Tauchen, and Newey 1985
|
This pull request introduces 1 alert when merging da5f2ec into c6a76ed - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
All green, but test coverage for the two code modules is still only 67 and 70 % I didn't remember that the all methods of computing score and robust score produce identical results, up to linalg floating point precision, at least for the OLS case: |
|
This pull request introduces 1 alert when merging e70db33 into c6a76ed - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
all Boos robust, generalized score test functions are now unit tested for OLS this PR is green numpy: 1.14.3 |
|
This pull request introduces 1 alert when merging ca84a6a into c6a76ed - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
this time all green the last commit added one test case for I'm postponing a full testing for it to when I go back to diagnostic tests. For example The point of
|
|
I'm pretty sure this should us uncentered rsquared, so is currently only correct if there is no constant in the OLS regression. comparing with dispersion test most tests in sandbox diagnostics for OLS use rsquared, not uncentered rsquared. het_white and het_breuschpagan don't include a restriction on the constant in the hypothesis test, i.e. resid**2 can be any constant, but slope coefficients should be zero. |
|
|
||
| - fit_constrained result: model contains score and hessian function for | ||
| the full, unrestricted model, but the parameter estimate in the results | ||
| instance are for the restricted model. This is the case if the model |
| k_constraints : int or None | ||
| Number of constraints that were used in the estimation of params | ||
| restricted relative to the number of exog in the model. | ||
| This must be provided if no exog_extra are given. If exog_extra is |
There was a problem hiding this comment.
outdated: k_constraints is not necessary anymore.
Inferred from constraints attribute added by fit_constrained, if not provided
There was a problem hiding this comment.
I leave it in for now as override possibility.
There is a path if constraints attribute is not available, e.g. fit_zeros doesn't have it.
| matrix. | ||
|
|
||
| cov_type is 'HC0' | ||
|
|
| cov_score = nobs * np.cov(score_obs.T) | ||
| V = self.cov_params_default | ||
| # temporary to try out | ||
| chi2stat = _lm_robust(score, r_matrix, hinv, cov_score, V=V) |
There was a problem hiding this comment.
cov_score should be None in this case
|
I had an old review open. Now all addressed or ignored with comment. Merge when green. Next up: most likely enhancing discrete with offset and score factor, and then adding score_test to results classes in discrete and GLM. |
|
This pull request introduces 2 alerts when merging 67ef53d into d8cb151 - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
This pull request introduces 1 alert when merging dbbfc52 into d8cb151 - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
again one of the vecm lag order selection test fails on one python on travis otherwise green, merging |
first round of adding generic robust score/LM and conditional moment tests
see #2041 for summary issue
most generic tests have unit tests for OLS case
some generic functions are untested
also includes GLM specific cm/lmtest, and Poisson over/under dispersion tests, no test coverage
I might want to merge this with only variable addition as verified use case and leave other applications and extensions for another PR.
Note: efficient GMM (with optimal weighting matrix): weighting matrix is irrelevant if we estimate with exactly identified model. However, Newey West say that the optimization like (Q)MLE or M-estimator with constraints is not efficient. (refering to CMT in Newey 1985 GMM versus Newey/West efficient GMM)
TODO
Extensions
For the next two it is not clear yet whether the generic/general case can handle those. My guess is that it should be covered already.
example Wooldridge variance tests in GLM/LEF joint with mean
This looks just like a test on only some of the overidentifying restrictions but partialling out all other alternatives, but I haven't verified that yet.