Skip to content

Comparing linear models using lagrange multiplier tests - #1174

Closed
bashtage wants to merge 25 commits into
statsmodels:masterfrom
bashtage:compare-lr-test
Closed

bashtage wants to merge 25 commits into
statsmodels:masterfrom
bashtage:compare-lr-test

Conversation

@bashtage

@bashtage bashtage commented Nov 3, 2013

Copy link
Copy Markdown
Member

This pull request adds a method to compare models using LM tests which are robust to heteroskedasticity and autocorrelation (if the covariance used is HC or HAC).

  • Added compare_lm_test which implements the test
  • Added _is_nested which tests whether models are nested
  • Added `_has_constant' which can correctly detect whether a set of regressors contains a constant or constant-like variable (i.e. all dummies such that the sum is 1 or a variable which is constant but !=1.0)
  • Added a large sample LR test
  • Tests to cover everything but _has_constant

This requires the changes needed to allow results with HC/HAC covariances and so may not be the right track.

…ts when the weight matrix or sigma are diagonal with the same values
Fixed loglikelihood in WLS
Lots of Typo fixed in docstrings
PEP8 fixes
Added _is_nested method to detect nested models
BUG: Fixed bug in test for OLS/GLS/WLS equivalence
… in loglike

ENH: Many typos fixed
ENH: Better PEP8 compliance in a few places
Fixed test for summary which was failing due to now mandatory cov_type
Added additional OLS/WLS/GLS equivalence tests
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
… in loglike

ENH: Many typos fixed
ENH: Better PEP8 compliance in a few places
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling cab0957 on bashtage:compare-lr-test into 831e2ad on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

Kevin, Thank you for getting involved in and contributing to statsmodels.

It will take me some time to work through this. WLS is not matching the llf of Stata anymore, we have the same difference ll(model) - ll(null) but the absolute value is different. ( ll(null) is constant only regression)
I started to read the corresponding chapters in the Stata manual for the first time, but don't see yet what's different.
(Related: the Stata manual also mentions for several of the post estimation and diagnostic test whether they are valid with robust standard errors or whether they assume i.i.d. errors.)

I guess this PR also needs some git surgery to clean up some commits and to remove the "Merged in robust covariance changes".

@bashtage

bashtage commented Nov 3, 2013

Copy link
Copy Markdown
Member Author

My git sills are definitely lacking. I made a real mess of my branch at some point and tried to work back to something more same.

For example, I made the changes to the WLS loglike but didn’t mean to put those in the pull request following on our previous exchange where I though this required its own treatment.

From: Josef Perktold [mailto:[email protected]]
Sent: Sunday, November 3, 2013 8:17 PM
To: statsmodels/statsmodels
Cc: Kevin Sheppard
Subject: Re: [statsmodels] Comparing linear models using lagrange multiplier tests (#1174)

Kevin, Thank you for getting involved in and contributing to statsmodels.

It will take me some time to work through this. WLS is not matching the llf of Stata anymore, we have the same difference ll(model) - ll(null) but the absolute value is different. ( ll(null) is constant only regression)
I started to read the corresponding chapters in the Stata manual for the first time, but don't see yet what's different.
(Related: the Stata manual also mentions for several of the post estimation and diagnostic test whether they are valid with robust standard errors or whether they assume i.i.d. errors.)

I guess this PR also needs some git surgery to clean up some commits and to remove the "Merged in robust covariance changes".

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1174#issuecomment-27653038.

@josef-pkt

Copy link
Copy Markdown
Member

I will try to clean up the merges and rebase it before looking again at the details.

@josef-pkt

Copy link
Copy Markdown
Member

I get repeated merge conflict so I cannot rebase without going through all changes in detail.
I expect more merge conflicts when the other two PRs #1173 and #1176 are merged.

The initial commit of this PR looks duplicate with different content.
For example bashtage@8b9083d#diff-b16dd7e66ce2f7f160d0ef94e2fb40feR1281
show equations that disappeared in the final set of changes. And the final docstring is written with missing parts, start in middle of sentence.

I might try to break up this PR into separate pieces, or figure out how to squash selectively some commits, or just redo some changes from scratch.

Two changes to the substance:

  • I will copy the original compare_lr_test first to the base.LikelihoodModelResults so we can make the RegressionResults specific changes here. And later expand those to other models as far as that's possible.
  • I don't like that compare_lm_test is starting another list of sandwiches (after GMM and get_robustcov_results). It's good to see the pattern and I think we can still merge it. However, this should all go into a generalization of the sandwich calculations in statsmodels.stats.sandwich_covariance, so we can delegate without repeating the code, and reuse it also for discrete_model.

@bashtage

bashtage commented Dec 1, 2013

Copy link
Copy Markdown
Member Author

So should I forget my master and work from yours?

@josef-pkt

Copy link
Copy Markdown
Member

So should I forget my master and work from yours?
Yes, this one should be easy to merge into statsmodels master, while with your master I would have to go through the rebase and merge conflicts again.

If this looks roughly ok, then we could also merge this PR (and the other two) very soon, and then start new branches to continue the work.

@bashtage

bashtage commented Dec 1, 2013

Copy link
Copy Markdown
Member Author

I think that would allow for progress. I didn’t see anything out of order, but I’ll be sure to go through the merged code.

@josef-pkt josef-pkt closed this in fe97936 Dec 11, 2013
@bashtage
bashtage deleted the compare-lr-test branch March 24, 2014 23:16
PierreBdR pushed a commit to PierreBdR/statsmodels that referenced this pull request Sep 2, 2014
@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected Used for PRs with changes that are not acceptable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants