Skip to content

GEE commit - #928

Closed
kshedden wants to merge 49 commits into
statsmodels:masterfrom
kshedden:master
Closed

kshedden wants to merge 49 commits into
statsmodels:masterfrom
kshedden:master

Conversation

@kshedden

Copy link
Copy Markdown
Contributor

Here is the code for generalized estimating equations that we discussed on the mailing list.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the new signature this will be able to inherit statsmodels.base.model.Model which gives us the data handling and the from_formula method to build up the exog.

@josef-pkt

Copy link
Copy Markdown
Member

I got so excited I started to look at the code before checking the pull request

git/github: Pull request looks good, no problems. However, you are using your master branch instead of a feature branch. It's better to keep master to be able to mirror upstream/master (that is statsmodels/statsmodels/master).
One possibility: rename your current master branch to gee, and checkout a new master branch from the statsmodels remote. (I only know how to do this with git gui, and never tried in the middle of a pull request.)

I did a quick browsing of parts of the code.

Overall, I think the pull request looks very good.
The family parts integrate well with genmod.
The basic model signature is now in a way that the generic data handling should be able to do the first parts of initialization. I think the model class will be able to subclass base.model.Model without much work or problems.

I'm not so sure yet about inheritance for the results class, I haven't looked yet in detail, but I guess only base.model.Results is a possible candidate for the super class, and that might not bring much.
robust RLMResults inherits from LikelihoodModelResults, but there are some parts that don't really apply to models that are not based on Maximum Likelihood Estimation.
We discussed in the context of other new models (like Quantile Regression) that we will need either new Results classes or new Mixin classes in base.model so we have more targeted base classes to inherit common methods (like Wald tests).
maybe I can say more after looking more at the results for gee

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be called on each individual x (x for each group) or could this use the stacked x?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can follow the pattern of GLM.__init__
add groups and time as keyword arguments to the super __init__ call, and it will automatically check all arrays that have the same length as endog and exog for missing values at the same time, and drop the missing values in all of them, endog, exog, group and time.
In the GLM case, offset and exposure are extra (nobs, ) arrays.

GLM uses self._check_inputs(family, offset, exposure, endog) to verify the extra inputs.
Because the generic missing handling uses the length of the arrays to identify extra data variables, it cannot and doesn't verify that users used the right shape for those variables.

@josef-pkt

Copy link
Copy Markdown
Member

general comment:

interface and naming for this kind of model:

  • the input to the Model GEE now uses full arrays/dataframes (endog, exog, groups, time)
  • internally, most work is done using the list of individual arrays
  • I think it would be best if the output follows again the original stacked pattern (minus dropped missing rows)
    • as far as I can tell: predict, fittedvalues and resid can be based on dot(exog, param) instead of looping over individuals
    • if those results are full arrays, then we can use the generic code to wrap them into pandas data frames on return.
    • I guess we might be able to reuse some other residual and results diagnostics, if we have them as single arrays instead as list of arrays.

Following this, we should keep endog exog as name for the original, missing cleaned, data, and rename the list of individual arrays to something else that indicates it's the internal working data, endog_li li for list ? or something like that.

(This would apply then also to a rewrite of Mixed in the sandbox, and others.)

@josef-pkt

Copy link
Copy Markdown
Member

I opened #929 for possible additional result statistics.

@kshedden

kshedden commented Jul 1, 2013

Copy link
Copy Markdown
Contributor Author

I think I have addressed most or all of the issues mentioned above and pushed the changes to kshedden/statsmodels master branch.

@josef-pkt

Copy link
Copy Markdown
Member

I might have been wrong about the error for the file path of the csv files.
Currently, the TravisCI tests are failing, I think because we don't include the csv files in the source distribution.
I will look into this, it will need most likely changes in the setup.py of statsmodels
but then I won't have time to review the changes for a few days, or maybe only for a quick look.

@josef-pkt

Copy link
Copy Markdown
Member

two options for the csv files

  1. move them to the genmod/tests/results folder where they will be picked up automatically, or
  2. add the data folder to setup.py (toplevel statsmodels):

in setup.py after line 487
packages.append("statsmodels.tsa.vector_ar.data")
add

packages.append("statsmodels.genmod.tests.data")
package_data.update({"statsmodels.genmod.tests.data" : ["*.csv"]})

I think this should work, but often I need to use trial and error to figure out whether files are picked up.

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 7eb047f on kshedden:master into * on statsmodels:master*.

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling b06a46c on kshedden:master into * on statsmodels:master*.

@kshedden

kshedden commented Oct 8, 2013

Copy link
Copy Markdown
Contributor Author

Thanks for all the comments. I've addressed a number of them. If you think it is ready to merge now, let me know if/how to do it.

Some issues for the future:

  • Try to import rather than cut and paste some of the margins code.
  • Figure out how to specify constraints using formulas.
  • Speed up some of the covariance estimators
  • More tests
  • Documentation and examples

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offset could be None
I don't know if self.offset could also be None
(I'm looking at the test coverage on coveralls.io)

@vincentarelbundock

Copy link
Copy Markdown

@josef-pkt would it help if I "adopted" this pull request and made the changes myself to finalize this?

@josef-pkt

Copy link
Copy Markdown
Member

We should be able to get 0.5.1 out before the end of coming week, if we don't get any unforeseen problems.

Then we need to rebase this PR on master. I guess there will some merge conflicts in a PR that cleaned up links that's now in master.

After that, you or we can "finalize" either before merge or afterwards in a new PR.
Main thing will be to add it with examples to the documentation. Because it is a big enhancement, we need to document and advertise it well for 0.6.

Test coverage is above 80% but can be improved in several spots. (maybe additional regression test or cross checks)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be run during the nose test run

It's included in the coverage report, so I guess that nosetests identifies this is a test file, anything starting or ending with tests or test

@kshedden

Copy link
Copy Markdown
Contributor Author

Josef,

Feel free to adopt this pull request and handle whatever needs to be done
to get it merged. I am not very good with git and may just mess it up if I
try to do more right now. I think the current version is usable and I will
submit additional small pull requests against it after it is merged.

I will put together some examples.

I think all the other comments that you made today relate to parts of
genmod that I didn't write.

Kerby

On Sun, Oct 27, 2013 at 3:00 PM, Josef Perktold [email protected]:

We should be able to get 0.5.1 out before the end of coming week, if we
don't get any unforeseen problems.

Then we need to rebase this PR on master. I guess there will some merge
conflicts in a PR that cleaned up links that's now in master.

After that, you or we can "finalize" either before merge or afterwards in
a new PR.
Main thing will be to add it with examples to the documentation. Because
it is a big enhancement, we need to document and advertise it well for
0.6.

Test coverage is above 80% but can be improved in several spots. (maybe
additional regression test or cross checks)

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

@josef-pkt

Copy link
Copy Markdown
Member

Thanks Kerby,

Vincent and I will take over than until this is merged. We will appreciate if you stay the main "maintainer" of it, since you know the code best. I know the principle outline of this GEE implementation but never figured out all the details.

@vincentarelbundock It would be very good if you "adopt" this. I can review again before we merge it.
Unfortunately, something unforseen happened and Skipper won't be able to work on the release this week.
I think it's fine to rebase this on master, you can do it, or I can do it tomorrow.

@kshedden

Copy link
Copy Markdown
Contributor Author

Josef,

Yes, I will be happy to continue to maintain and develop this code. As
soon at it is merged I will check out a fresh copy and start adding more
tests.

Kerby

On Mon, Oct 28, 2013 at 11:24 PM, Josef Perktold
[email protected]:

Thanks Kerby,

Vincent and I will take over than until this is merged. We will appreciate
if you stay the main "maintainer" of it, since you know the code best. I
know the principle outline of this GEE implementation but never figured out
all the details.

@vincentarelbundock https://github.com/vincentarelbundock It would be
very good if you "adopt" this. I can review again before we merge it.
Unfortunately, something unforseen happened and Skipper won't be able to
work on the release this week.
I think it's fine to rebase this on master, you can do it, or I can do it
tomorrow.

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

@vincentarelbundock

Copy link
Copy Markdown

@kshedden thanks a lot. This is very exciting new stuff!

@josef-pkt one possibility would be to merge this into a GEE branch. I could then make a PR against that branch with all the changes. Would keep master clean until we can iron out the kinks. I should be able to spend a bit of time on this tonight or tomorrow.

@josef-pkt

Copy link
Copy Markdown
Member

@vincentarelbundock Yes, I can create a rebased GEE branch under statsmodels within a few hours.
Except for backporting from master to 0.5.1 (which might become more difficult if there are a lot of 0.6 commits), master is already at 0.6 and we have a bit of time to iron out kinks even after it's in master.

@vincentarelbundock

Copy link
Copy Markdown

Cool. I'll go through your comments on that branch and make a check list of things I haven't addressed so information carries over from this PR.

@josef-pkt

Copy link
Copy Markdown
Member

rebased in https://github.com/statsmodels/statsmodels/tree/gee_rebased

I didn't get any merge conflicts (no conflicts in links.py that I expected)
From a rough look, everything seems fine.

@josef-pkt

Copy link
Copy Markdown
Member

BTW: merging this will push us above the 100,000 lines of code mark according to http://www.ohloh.net/p/statsmodels/analyses/latest/languages_summary
(Time to delete some sandbox code to get below again. :)

@josef-pkt

Copy link
Copy Markdown
Member

@vincentarelbundock Are you working on this?

Skipper backported the changes from master to 0.5.1, and we can start to merge the bigger PRs for 0.6 into master.
I'd like to start reviewing and merging PRs in the next weeks (while also getting my robust_cov and IV/GMM branches ready for merge).

@vincentarelbundock

Copy link
Copy Markdown

I've been completely swamped with dissertation-related things. Had to put this on the backburner. I'll look at it tonight to see how much work is involved and will either do it or let you know if I can't.

Sorry about that.

@josef-pkt

Copy link
Copy Markdown
Member

@vincentarelbundock No problem. Dissertation deadlines on the horizon,. And still a long way to go. (?)

Push any changes if you have any, and I will look at it soon.

@vincentarelbundock

Copy link
Copy Markdown

Yes, need to defend this spring (starting new job in June). Don't know about "a long way", but certainly more work left than I was hoping for at this point. But, you know, everyone says that...

@vincentarelbundock vincentarelbundock mentioned this pull request Nov 30, 2013
1 task
@josef-pkt josef-pkt mentioned this pull request Dec 19, 2013
@josef-pkt josef-pkt closed this in 5a731a3 Dec 19, 2013
PierreBdR pushed a commit to PierreBdR/statsmodels that referenced this pull request Sep 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants