Skip to content

New PR for MICE - #2076

Merged
josef-pkt merged 17 commits into
statsmodels:masterfrom
kshedden:mice2
Nov 14, 2015
Merged

josef-pkt merged 17 commits into
statsmodels:masterfrom
kshedden:mice2

Conversation

@kshedden

@kshedden kshedden commented Nov 2, 2014

Copy link
Copy Markdown
Contributor

Frank and I decided that I should resubmit a MICE PR from my account due to time limitations on his side.

This PR supercedes #1757. It is a substantial overhaul of the code, but still contains all the main elements as designed and implemented by Frank in his GSOC project.

Here are two notebooks that illustrate how it can be used:

[Dead links, see below for updated working links]

http://nbviewer.ipython.org/urls/umich.box.com/shared/static/dkinhqyyz374k37tdwdi.ipynb

http://nbviewer.ipython.org/urls/umich.box.com/shared/static/pt8p8tctkl10t32xo97v.ipynb

Feedback welcome and encouraged.

@kshedden kshedden mentioned this pull request Nov 2, 2014
@jseabold jseabold added this to the 0.7 milestone Nov 21, 2014
@josef-pkt josef-pkt modified the milestones: 0.8, 0.7 Feb 4, 2015
@josef-pkt josef-pkt mentioned this pull request Feb 8, 2015
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 83.24% when pulling 4ea4911 on kshedden:mice2 into 9ff019f on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

just a quick look:
what happened to get_distribution attached to the existing models? Are they not needed anymore?

test coverage in this PR is considerably lower than in #1757, looks like just some smoke tests. Can the old tests be ported to this?

@josef-pkt

Copy link
Copy Markdown
Member

The notebooks and plots in it look very nice.

@kshedden

kshedden commented Feb 9, 2015

Copy link
Copy Markdown
Contributor Author

At some point we decided to pull back a bit and focus on predictive mean matching. PMM seems to work quite well and apparently is the favored choice in other packages. I thought it made sense to focus on other features like diagnostic plots rather than to continue wrestling with get_distribution.

I would be happy to get some feedback on the MICE implementation and can put time into upgrading the branch as needed.

I will look into improving test coverage.

@josef-pkt

Copy link
Copy Markdown
Member

Hopefully @agartland can provide feedback. I can give a brief review after 0.7, but I have also several other PRs that I have kept waiting for too long.

@kshedden Can you give a brief summary of the difference of this version and Franks #1757 version, especially with respect to what's in 1757 and not in here. Based on your last comment I assume that there are still things in 1757 that are not obsolete and might be ported to the new version at some point.

Comment thread statsmodels/sandbox/mice/mice.py Outdated

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.

something like MICE is the wrapper class that does the full analysis, ....
IIUC, to get the contrast between the function that holds some pieces and the top class

@josef-pkt

Copy link
Copy Markdown
Member

missing test coverage looks mostly missing smoke tests for hist plot method (*) and summary method

(*) plot methods in models or results should have plot_ prefix in name

I'll try to finish my review tomorrow.

Comment thread statsmodels/sandbox/mice/mice.py Outdated

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.

Do we need that the class itself is an iterator?

When Skipper and I took over stats.models we removed all iterators from the classes and converted them to iteration loops inside methods. The main problem is that it is very difficult to keep track what is actually changed and where the side effects are of the iterator.

I haven't looked at a specific example yet, this is just general skepticism to possibly difficult to understand code.

@josef-pkt

Copy link
Copy Markdown
Member

possible bug in summary2 (bug in column label) label is for t distribution, even if it's using normal?

Usecase: How do we handle repeated fitting during model search, evaluating different models? Do we have to start from scratch each time to get replicable random numbers given initial seed?
(extension to this for followup?)

@josef-pkt

Copy link
Copy Markdown
Member

I don't see test coverage for pvalues and confint. We have helper test functions to test consistency with normal or t distribution (given that we had some refactoring bugs with inherited pvalues and confint in the past.)
Given the discussion last year during GSOC, we should also check that the correct df are used if the distribution is t. If there are ambiguities in which df to use, then our choice should be documented.

Comment thread statsmodels/sandbox/mice/mice.py Outdated

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.

Storing the entire results can become memory intensive. I've done the same in adfuller, and user feedback was that the memory consumption goes up a lot with large arrays and many imputations/results. For the combine support we would only need to store params and scale and store or accumulate cov_params.
(storing full results could be optional or users could use a callback.)

@josef-pkt

Copy link
Copy Markdown
Member

Stata manual says they are using t distribution with missingness dependent degrees of freedom if number of imputations is small. (They mention normal distribution for large number of imputation, but without mentioning threshold and in a quick browsing I only see t distribution params tables. Some examples show "df adjustment: large sample", but still have "p>|t|" as column header. also "Model F-test: equal FMI")

@josef-pkt

Copy link
Copy Markdown
Member

to summarize:

The plot methods need to be renamed to start with plot_ for API consistency.

I'm not very happy about the iterator in MICE. (vague, because it might not be needed, and makes the class more complex than necessary.) If possible it would be better to change this before merging.

All the other issues can wait for a followup

  • use of t distribution looks fine, but we need tests and possibly more code or review of inherited methods for other inference.
  • restarting, storage, ..., are usability questions and can be changed over time.
  • some code and memory streamlining could be now or later.

I haven't tried to understand all the details.

Overall I think the structure looks very good and flexible, and I expect that we will get many opportunities to build on and extend this.

Can we add any of your notebooks to the documentation notebook examples?

@kshedden

Copy link
Copy Markdown
Contributor Author

@kshedden

Copy link
Copy Markdown
Contributor Author

I set pdf_output = False and added a smoke test for summary.

@josef-pkt

Copy link
Copy Markdown
Member

Thanks @kshedden

I'll merge when travis reports back

Do you have an opinion about directory name and location?

My initial thought was to use one folder for treatment and imputation, but now I think we just use two directories, and we can move this into statsmodels/imputation (in the next PR).

josef-pkt added a commit that referenced this pull request Nov 14, 2015
@josef-pkt
josef-pkt merged commit c09c1b8 into statsmodels:master Nov 14, 2015
@kshedden

Copy link
Copy Markdown
Contributor Author

Thanks. I don't have an opinion about directory location.

On Sat, Nov 14, 2015 at 1:44 PM, Josef Perktold [email protected]
wrote:

Merged #2076 #2076.

—
Reply to this email directly or view it on GitHub
#2076 (comment).

@cschwem2er

Copy link
Copy Markdown

Wow I am looking for a Python MICE implementation since several months, thank you so much for this work! Any idea when this will be included in statsmodels?

@kshedden

Copy link
Copy Markdown
Contributor Author

It's in. If you have any questions or suggestions after using it email the
list:

https://groups.google.com/forum/#!forum/pystatsmodels

or open an issue on github.

On Sat, Nov 14, 2015 at 6:08 PM, Carsten Schwemmer <[email protected]

wrote:

Wow I am looking for a Python MICE implementation since several months,
thank you so much for this work! Any idea when this will be included in
statsmodels?

—
Reply to this email directly or view it on GitHub
#2076 (comment)
.

@datnamer

Copy link
Copy Markdown

Nice!!!

@donaldbraman

donaldbraman commented Apr 17, 2016 •

Copy link
Copy Markdown

Just wanted to say thank you for this. Happy to be able to do one more thing in Python that was previously only possible in R.

@josef-pkt josef-pkt mentioned this pull request Jun 10, 2016
2 tasks done
@josef-pkt

josef-pkt commented Jun 10, 2016 •

Copy link
Copy Markdown
Member

Note: PR #3000 is moving mice to statsmodels.imputation.mice
There is currently no compatibility layer, for those already using it

@kshedden
kshedden deleted the mice2 branch July 1, 2016 03:59
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.

7 participants