The mice function is one of the most used functions to
apply multiple imputation. This page shows how functions in the
psfmi package can be easily used in combination with
mice. In this way multivariable models can easily be
developed in combination with mice.
You can install the released version of psfmi with:
And the development version from GitHub with:
You can install the released version of mice with:
library(psfmi)
library(mice)
#>
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following objects are masked from 'package:base':
#>
#> cbind, rbind
imp <- mice(lbp_orig, m=5, maxit=5)
#>
#> iter imp variable
#> 1 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
data_comp <- complete(imp, action = "long", include = FALSE)
library(psfmi)
pool_lr <- psfmi_lr(data=data_comp, nimp=5, impvar=".imp",
formula=Chronic ~ Gender + Smoking + Function +
JobControl + JobDemands + SocialSupport, method="D1")
pool_lr$RR_model
#> $`Step 1 - no variables removed -`
#> term estimate std.error statistic df p.value
#> 1 (Intercept) 0.066229171 2.46025406 0.02691965 115.5580 0.978570257
#> 2 Gender -0.357393612 0.41326871 -0.86479716 147.1767 0.388557483
#> 3 Smoking 0.076537937 0.33978776 0.22525219 148.6868 0.822092384
#> 4 Function -0.142107921 0.04338159 -3.27576572 142.7679 0.001322715
#> 5 JobControl 0.008682984 0.02017632 0.43035522 118.2583 0.667720538
#> 6 JobDemands -0.002853404 0.03742667 -0.07623986 122.1444 0.939353010
#> 7 SocialSupport 0.043561492 0.05652205 0.77069905 147.1041 0.442121387
#> OR lower.EXP upper.EXP
#> 1 1.0684716 0.008173889 139.6680845
#> 2 0.6994971 0.309096772 1.5829871
#> 3 1.0795431 0.551618424 2.1127166
#> 4 0.8675276 0.796234803 0.9452038
#> 5 1.0087208 0.969213157 1.0498389
#> 6 0.9971507 0.925943216 1.0738341
#> 7 1.0445242 0.934130981 1.1679635Back to Examples
library(psfmi)
library(mice)
imp <- mice(lbp_orig, m=5, maxit=5)
#>
#> iter imp variable
#> 1 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 1 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 2 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 3 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 4 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 1 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 2 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 3 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 4 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
#> 5 5 Carrying Pain Tampascale Function Radiation Age Satisfaction JobControl JobDemands SocialSupport
data_comp <- complete(imp, action = "long", include = FALSE)
library(psfmi)
pool_lr <- psfmi_lr(data=data_comp, nimp=5, impvar=".imp",
formula=Chronic ~ Gender + Smoking + Function +
JobControl + JobDemands + SocialSupport,
p.crit = 0.157, method="D1", direction = "FW")
#> Entered at Step 1 is - Function
#>
#> Selection correctly terminated,
#> No new variables entered the model
pool_lr$RR_model_final
#> $`Final model`
#> term estimate std.error statistic df p.value OR
#> 1 (Intercept) 1.3009744 0.46758652 2.782318 145.6272 0.0061125867 3.6728737
#> 2 Function -0.1468001 0.04163259 -3.526085 144.1331 0.0005658864 0.8634666
#> lower.EXP upper.EXP
#> 1 1.4576740 9.254470
#> 2 0.7952575 0.937526Back to Examples