Repository navigation
BUG: MICEData sets initial imputation incorrectly - #5301
Conversation
|
Failling this test in statsmodels.imputation.test.test_mice.py def test_combine(self):
np.random.seed(3897)
x1 = np.random.normal(size=300)
x2 = np.random.normal(size=300)
y = x1 + x2 + np.random.normal(size=300)
x1[0:100] = np.nan
x2[250:] = np.nan
df = pd.DataFrame({"x1": x1, "x2": x2, "y": y})
idata = mice.MICEData(df)
mi = mice.MICE("y ~ x1 + x2", sm.OLS, idata, n_skip=20)
result = mi.fit(10, 20)
fmi = np.asarray([ 0.1920533 , 0.1587287 , 0.33174032])
assert_allclose(result.frac_miss_info, fmi, atol=1e-5)
params = np.asarray([-0.05397474, 0.97273307, 1.01652293])
assert_allclose(result.params, params, atol=1e-5)
tvalues = np.asarray([ -0.84781698, 15.10491582, 13.59998039])
assert_allclose(result.tvalues, tvalues, atol=1e-5)I have not confirmed yet by manually calculating, but I am thinking the numbers in hard coded arrarys are based on the MICEData code bug that assigns distance from the mean, and not actual mean of a column. |
|
@jtweeder Thanks, this looks correct to me. The currently failing test is a regression test, so you should change the hard-coded constants to whatever you are getting with the new code. Would it be possible to write a test that confirms that the set of unique values in each column does not change when doing mice imputation? That test would have caught this issue. |
|
One Travis job is failing at the |
|
Just some experimenting around shows that testpath=0.4.1 from conda-forge is the culprit for the docbuild failure. conda-forge/testpath-feedstock#7 Thats fixed in version 0.4.2 which is coming soon to a travis build near you: conda-forge/testpath-feedstock#8 I'd suggest waiting a day a two and re-pushing once conda-forge is pushing the newer testpath. |
Codecov Report
@@ Coverage Diff @@
## master #5301 +/- ##
==========================================
+ Coverage 81.71% 81.71% +<.01%
==========================================
Files 569 569
Lines 89710 89712 +2
Branches 10028 10030 +2
==========================================
+ Hits 73306 73308 +2
Misses 14132 14132
Partials 2272 2272
Continue to review full report at Codecov.
|
Previous code only imputed value as the distance from the mean for the closest observed value.
1a09456 to
03bbf92
Compare
|
Thanks @jtweeder, I am merging now |
Previous code only imputed value as the distance from the mean for the closest observed value, and not actually the observed value when MICEData is initialized.
closes #5254