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.508359142 2.45367455 -0.2071828 110.4099 0.8362487384
#> 2 Gender -0.325075074 0.41611434 -0.7812157 146.6882 0.4359346093
#> 3 Smoking 0.088247373 0.33976510 0.2597305 149.8911 0.7954280405
#> 4 Function -0.145180514 0.04305195 -3.3722166 145.1897 0.0009559145
#> 5 JobControl 0.010591705 0.01995331 0.5308244 131.3532 0.5964368694
#> 6 JobDemands 0.005176873 0.03753451 0.1379230 123.1386 0.8905265519
#> 7 SocialSupport 0.051886372 0.05639090 0.9201195 137.3550 0.3591234411
#> OR lower.EXP upper.EXP
#> 1 0.6014817 0.00465057 77.7926659
#> 2 0.7224731 0.31745202 1.6442403
#> 3 1.0922583 0.55816522 2.1374104
#> 4 0.8648662 0.79431909 0.9416788
#> 5 1.0106480 0.97153331 1.0513375
#> 6 1.0051903 0.93321509 1.0827167
#> 7 1.0532561 0.94212229 1.1774993Back 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.2309357 0.46848487 2.627482 138.6895 0.009570242 3.4244324
#> 2 Function -0.1405418 0.04185994 -3.357430 134.5592 0.001023193 0.8688873
#> lower.EXP upper.EXP
#> 1 1.3561363 8.6471675
#> 2 0.7998506 0.9438828Back to Examples