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.0732087959 2.58035463 0.028371603 74.11387 0.977442032
#> 2 Gender -0.3656032002 0.41379009 -0.883547491 147.37296 0.378379603
#> 3 Smoking 0.1045111860 0.34049266 0.306941079 149.28917 0.759315938
#> 4 Function -0.1422280109 0.04332718 -3.282650961 137.79160 0.001303293
#> 5 JobControl 0.0075585801 0.02041351 0.370273390 103.67036 0.711934213
#> 6 JobDemands -0.0002447744 0.04021589 -0.006086509 61.81800 0.995163298
#> 7 SocialSupport 0.0419682118 0.05602909 0.749043244 147.23418 0.455026160
#> OR lower.EXP upper.EXP
#> 1 1.0759552 0.006294187 183.9283666
#> 2 0.6937780 0.306256653 1.5716490
#> 3 1.1101678 0.566489838 2.1756305
#> 4 0.8674235 0.796203761 0.9450137
#> 5 1.0075872 0.967612391 1.0492135
#> 6 0.9997553 0.922525831 1.0834500
#> 7 1.0428613 0.933553616 1.1649676
Back 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.1987368 0.46296043 2.589286 140.6708 0.010628564 3.3159254
#> 2 Function -0.1383369 0.04129885 -3.349655 143.4305 0.001034044 0.8708053
#> lower.EXP upper.EXP
#> 1 1.3277386 8.2812700
#> 2 0.8025429 0.9448738
Back to Examples