`parameters()` does not extract needed columns for `mipo` objects
vincentarelbundock opened this issue · 2 comments
vincentarelbundock commented
The parameters()
function does not return all relevant columns for mipo
multiple imputation objects. For example, when estimating multinomial models, we should get a response
column, but we don’t:
library(mice)
library(nnet)
library(parameters)
data = ampute(mtcars) ## Ampute mtcars and impute two data sets
imp = mice(data$amp, m = 2)
imp.l = complete(imp, action = "long")
model = list() ## Fit and pool models
for (i in 1:2) model[[i]] = multinom(carb ~ disp + hp, data = imp.l, subset = .imp == i)
pooled = pool(model)
parameters(pooled)
# # Fixed Effects
#
# Parameter | Coefficient | SE | 95% CI | Statistic | p
# --------------------------------------------------------------------
# (Intercept) | -1.85 | 2.03 | [-6.18, 2.48] | -0.91 | 0.377
# disp | 6.51e-03 | 0.01 | [-0.02, 0.03] | 0.55 | 0.588
# hp | 0.01 | 0.03 | [-0.06, 0.08] | 0.35 | 0.729
# (Intercept) | -11.88 | 2.03 | [-6.18, 2.48] | -0.91 | 0.377
# disp | -0.03 | 0.01 | [-0.02, 0.03] | 0.55 | 0.588
# hp | 0.13 | 0.03 | [-0.06, 0.08] | 0.35 | 0.729
# (Intercept) | -10.95 | 2.03 | [-6.18, 2.48] | -0.91 | 0.377
# disp | -0.02 | 0.01 | [-0.02, 0.03] | 0.55 | 0.588
# hp | 0.13 | 0.03 | [-0.06, 0.08] | 0.35 | 0.729
# (Intercept) | -32.82 | 2.03 | [-6.18, 2.48] | -0.91 | 0.377
# disp | -6.88 | 0.01 | [-0.02, 0.03] | 0.55 | 0.588
# hp | 5.99 | 0.03 | [-0.06, 0.08] | 0.35 | 0.729
# (Intercept) | -37.68 | 2.03 | [-6.18, 2.48] | -0.91 | 0.377
# disp | -0.57 | 0.01 | [-0.02, 0.03] | 0.55 | 0.588
# hp | 0.73 | 0.03 | [-0.06, 0.08] | 0.35 | 0.729
#
# Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed using a Wald distribution approximation.
The best way to deal with this would probably be to use the mice:::tidy.mipo()
method, which ships by default with mice
, and should thus always be available whenever the user has a mipo
object. Note the y.level
column at the very end, which is the one we need.
mice:::tidy.mipo(pooled)
# term estimate std.error statistic p.value b df dfcom fmi lambda m riv ubar y.level
# 1 (Intercept) -1.852990716 2.03453974 -0.9107665 0.37660359 1.102874e-02 1.523514e+01 17 0.1132365 0.003996547 2 4.012583e-03 4.122809e+00 2
# 2 disp 0.006513995 0.01176502 0.5536747 0.58830509 3.589520e-06 1.438477e+01 17 0.1494675 0.038899332 2 4.047373e-02 1.330315e-04 2
# 3 hp 0.011120602 0.03154816 0.3524960 0.72945522 1.755040e-05 1.474169e+01 17 0.1361974 0.026450282 2 2.716891e-02 9.689608e-04 2
# 4 (Intercept) -11.877096615 4.67299293 -2.5416466 0.02235546 4.321350e-02 1.525253e+01 17 0.1122170 0.002968386 2 2.977224e-03 2.177204e+01 3
# 5 disp -0.029333751 0.02030589 -1.4445936 0.16883125 1.185566e-06 1.522970e+01 17 0.1135509 0.004312936 2 4.331618e-03 4.105506e-04 3
# 6 hp 0.134618347 0.06203947 2.1698824 0.04625323 1.430839e-05 1.520749e+01 17 0.1148087 0.005576297 2 5.607567e-03 3.827433e-03 3
# 7 (Intercept) -10.954181418 4.36789413 -2.5078862 0.02391829 4.721884e-02 1.524000e+01 17 0.1129545 0.003712465 2 3.726299e-03 1.900767e+01 4
# 8 disp -0.024111291 0.01854744 -1.2999798 0.21293953 9.900675e-07 1.522963e+01 17 0.1135550 0.004317062 2 4.335780e-03 3.425223e-04 4
# 9 hp 0.127845630 0.05976495 2.1391407 0.04904225 1.357680e-05 1.520525e+01 17 0.1149337 0.005701585 2 5.734279e-03 3.551484e-03 4
# 10 (Intercept) -32.820498916 2.15430280 -15.2348588 0.99315334 3.093918e+00 4.710637e-04 17 0.9999897 0.999969197 2 3.246338e+04 1.429573e-04 6
# 11 disp -6.880753231 4.54316572 -1.5145283 0.90370842 1.372584e+01 3.684304e-02 17 0.9991466 0.997500322 2 3.990516e+02 5.159423e-02 6
# 12 hp 5.993956276 3.79909400 1.5777331 0.83682645 9.572496e+00 7.313213e-02 17 0.9982006 0.994847157 2 1.930676e+02 7.437157e-02 6
# 13 (Intercept) -37.679041139 0.51623460 -72.9882139 0.97967691 1.776354e-01 2.578597e-03 17 0.9999436 0.999831029 2 5.917164e+03 4.503055e-05 8
# 14 disp -0.566960948 0.30634672 -1.8507166 0.17811331 3.198792e-02 2.530805e+00 17 0.6880006 0.511270642 2 1.046122e+00 4.586643e-02 8
# 15 hp 0.726340764 0.30756516 2.3615834 0.08095960 2.485393e-02 3.799515e+00 17 0.5723222 0.394105145 2 6.504514e-01 5.731543e-02 8
Unfortunately, I don’t have the bandwidth right now to work on this, but I thought I’d open an issue anyway
strengejacke commented
Thanks, should be fixed after merging the two referenced PRs.
vincentarelbundock commented
This is awesome, thanks a ton!