Compare lr test rebased #1214

merged 14 commits into from Dec 11, 2013


None yet

3 participants


rebased and cleaned up version of @bashtage PR #1174

I skipped some redundant commits, and edited the commits during merge conflicts (in almost every commit).

Main change besides cleanup of reverted and unnecessary commits is in default cov_type="nonrobust" especially commit 4d517f5

A second change that I kept from my sandwich branch and didn't change during rebase is that the default is use_t=None not use_t=False. A minor generic reason is that in this case we can identify if the user explicitly specifies use_t. The main reason is that None means default, which will be use_t=True with cov_type='nonrobust' in linear model, but I think also withcov_type='cluster', andFalse` for all other covariances and models.
Still up for debate.

I'd like to merge this before #1173 and #1176 because I saw one duplicate commit too late to drop it.

Discussion on cov_type="nonrobust"

#1189 (comment) and follow-up

I changed "H" for homoscedasticity to "nonrobust", both because I'm not a fan of one letter names (does H mean homo- or heteroscedasticity as in HCx), and because "nonrobust" doesn't imply that we assume homoscedasticity.

To the later point:

  • We can estimate a linear model with WLS that uses an estimated heteroscedasticity function (the wresid would be homoscedastic but not the resid if the specification is correct). However, we can still use either a robust or a nonrobust covariance matrix after estimating with WLS.
  • In Poisson and most other generalized linear models we have an implied heteroscedasticity. "nonrobust" means that the heteroscedasticity of the underlying (Q)MLE model is not assumed to be correctly specified.

Same applies to auto- or cluster correlation.

Plus, Wooldridge talks all the time of using robust or not robust covariance matrices or hypothesis tests.

So far I can think of only "nonrobust" that captures the idea that we are not robust to misspecification of the error covariance matrix. The opposite view would be the model has correctly specified second moments, but I don't know a good short name for that.

Kevin Sheppard and others added some commits Oct 30, 2013
@josef-pkt Kevin Sheppard Initial addition of heteroskedasticity robust LM and LR tests. dbff023
@josef-pkt Kevin Sheppard * Initial addition of heteroskedasticity robust LM and LR tests.
* Additional Clean up
@josef-pkt Kevin Sheppard Bug fixes for lr test 1001f50
@josef-pkt josef-pkt fixed typo defe1b1
@josef-pkt Kevin Sheppard Added test that check whether OLS, GLS and WLS produce the same resul…
…ts when the weight matrix or sigma are diagonal with the same values
@josef-pkt Kevin Sheppard Added basic tests for LM 85f1941
@josef-pkt Kevin Sheppard LM test now handles robust covariance
Fixed loglikelihood in WLS
Lots of Typo fixed in docstrings
PEP8 fixes
Added _is_nested method to detect nested models
rebase conflicts fixed, hopefully
@josef-pkt Kevin Sheppard Added tests for compare_lm_test
Fixed test for summary which was failing due to now mandatory cov_type
Added additional OLS/WLS/GLS equivalence tests
@josef-pkt Kevin Sheppard Added _has_constant function which can detect implicit constant
Added _is_nested to test whether models are nested when comparing models
Added compare_lm_test
Merged with get_robustvcv_result which is needed to implement tests
Added large sample likelihood-ratio test
Implemented cov_type for all models including homoskedastic regression.  Use 'H' for the homoskedastic case
heavily edited for 'nonrobust' instead of 'H' during rebase
@josef-pkt Kevin Sheppard ENH: Added method _has_constant which can correctly detect an implici…
…t constant
@josef-pkt Kevin Sheppard ENH: Normalization of weights in WLS and loglike correction 00d0f9f
@josef-pkt Kevin Sheppard ENH: Added cov_type for all models a36000b
@josef-pkt Kevin Sheppard Made tests tougher aad6bae

I didn't review yet the new functions in detail.

@bashtage do you see anything obvious that I might have messed up during rebase?

The test suite passes, and I would like to merge this soon, so we have again a common code for working on the next parts, with hopefully fewer merge conflicts next time.


Coverage Status

Coverage remained the same when pulling aad6bae on josef-pkt:compare_lr_test_rebased into a14d989 on statsmodels:master.

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
if has_robust1 or has_robust2:
import warnings
warnings.warn('Likelihood Ratio test is likely invalid with ' +
'robust covariance, proceeding anyway', UserWarning)
- # See mailing list discussion October 17,
+ if large_sample:
+ return self.compare_lr_test(restricted, use_lr=True)
josef-pkt Dec 1, 2013 Member

rebase error
this is duplicate from above line 1495 and should be deleted
call to compare_lm_test uses robust cov

@josef-pkt josef-pkt commented on the diff Dec 11, 2013
@@ -114,6 +135,24 @@ def df_resid(self):
def df_resid(self, value):
self._df_resid = value
+ def _has_constant(self):
josef-pkt Dec 11, 2013 Member

I think this should move to some place more general, to base or to tools (in follow-up PR)

bashtage Dec 13, 2013 Contributor

Makes sense. I think that this is a general technique that should be available to other models, e.g. glm.

@josef-pkt josef-pkt referenced this pull request Dec 11, 2013

Sandwich mle #1225


Coverage Status

Coverage remained the same when pulling 80acfff on josef-pkt:compare_lr_test_rebased into a14d989 on statsmodels:master.


merging this

Thank you Kevin,
I'm going to merge the other two PR next.
I don't remember now where the WLS=GLS change is because I don't see any test failures.

@josef-pkt josef-pkt merged commit fe97936 into statsmodels:master Dec 11, 2013

1 check passed

default The Travis CI build passed
@josef-pkt josef-pkt deleted the josef-pkt:compare_lr_test_rebased branch Dec 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment