Skip to content

Mice - #1757

Closed
chengfulun wants to merge 92 commits into
statsmodels:masterfrom
chengfulun:mice
Closed

Mice#1757
chengfulun wants to merge 92 commits into
statsmodels:masterfrom
chengfulun:mice

Conversation

@chengfulun

Copy link
Copy Markdown

This is a WIP PR. I have implemented a statsmodels class that receives a dataset with missing values and imputes the missing values using chained equations. It can then fit an analysis model to the fully imputed data. The code gives sensible results for a real dataset but has not been rigorously tested against existing software packages.

chengfulun added 30 commits May 4, 2014 03:13
Started building the simulation switchboard function and initialized the
simulate functions. Created class in mice.py for filling in imputations.
Imputer, ImputerChain, and AnalysisChain classes in mice.py, created
mice folder, inserted get_distribution switchboard into
LikelihoodModelResults in base folder.
halfway through modifying mice.py structure to support chained
equations. also did a first pass for OLS's MLE + noise simulation method
changed get_distribution and imputer to do simulation inside the
imputer, modified all the classes inside mice.py
Dry run working for linear model.
included my test data set, missingdata.csv in the test_mice file
ran some initial tests and cleaned up the code
minor changes to analysis chain, combining skeleton
implemented combining of parameter estimates for ImputerChain
Changed get_distribution to mirror the predict method and made sure the
new version returns the same thing as before up to ImputerCombine.
Added functionality for logistic regression in discrete. Had to create
fork in impute_asymptotic_bayes for now, may change design later. Also
finished the AnalysisChain class for doing MICE without saving any
datasets.
In process of changing ImputerChain class to iterator.
Got MICE method to work by doing away with self.data and instead
modifying/returning underlying data directly.
Fixed bug in calculating the perturbed parameter.
Changed scale passed to get_distribution, changed order of imputation so
that variable with least missing data is imputed first.
Working version of pmm imputation that matches fairly closely with
asymptotic bayes. More testing needed.
Fixed minor bug with usage of scale.
trying to return a results class
Added clarity in several places, and added functionality for pmm
choosing over several neighbors.
Made AnalysisChain and ImputerChain iterators. Added a bunch of helper
functions like new_imputer and changed store_changes. Added MissingData
class. Simplified user interface.
Add intercept if original model had intercept only.
Changes to pmm and docstrings
Fixed get_distribution seed issue, restructured MICE run and combine,
added method choosing parameters.
Changes to ImputedData and Imputer
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.

2 blank lines

@josef-pkt josef-pkt added the PR label Aug 1, 2014
Still pending: numpy instance clarification, add_imputations, pval
methods, blank lines, trailing whitepsace, and Rhistory.
@josef-pkt

Copy link
Copy Markdown
Member

general question on inference and degrees of freedom:

If the degrees of freedom for t-test and similar differ across parameters, how are the degrees of freedom determined for tests that involve several parameters.

For example, a t-test that two coefficients are the same, however the degrees of freedom for the two coefficients differ.

(A related thought, that can be ignored: For two sample t-test with unequal variance and unequal sample sizes we use Satterthwaite df correction which is a weighted average.)

I can help with the implementation for t-test confint, ... next week. I just added df_resid_inference as optional attribute to model when df_resid used in the hypothesis tests is different from nobs - k_vars, which I needed to do for cluster robust standard errors.

@chengfulun

Copy link
Copy Markdown
Author

I hadn't really thought of this, but the Satterthwaite correction may be
appropriate. Then I guess we are saying that each variable has a different
effective sample size and unequal variances, both of which are true. I
guess we would be ignoring any mutual information among the parameters
though. We do have a sample covariance matrix for the parameters, not just
the standard errors. I have to think about how to use it to get degree of
freedom weightings.

@kshedden kshedden mentioned this pull request Nov 2, 2014
@kshedden

kshedden commented Nov 2, 2014

Copy link
Copy Markdown
Contributor

Moved to #2076

@jseabold

Copy link
Copy Markdown
Member

Closing in favor of #2076.

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.

5 participants