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:
install.packages("psfmi")
And the development version from GitHub with:
# install.packages("devtools")
::install_github("mwheymans/psfmi") devtools
You can install the released version of mice with:
install.packages("mice")
library(psfmi)
library(mice)
<- mice(lbp_orig, m=5, maxit=5)
imp #>
#> 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
<- complete(imp, action = "long", include = FALSE)
data_comp
library(psfmi)
<- psfmi_lr(data=data_comp, nimp=5, impvar=".imp",
pool_lr formula=Chronic ~ Gender + Smoking + Function +
+ JobDemands + SocialSupport, method="D1")
JobControl $RR_model
pool_lr#> $`Step 1 - no variables removed -`
#> term estimate std.error statistic df p.value
#> 1 (Intercept) 0.256763455 2.43312414 0.1055283 134.4059 0.916113945
#> 2 Gender -0.359441075 0.41876991 -0.8583259 142.0828 0.392158157
#> 3 Smoking 0.067952121 0.33814663 0.2009546 149.5614 0.841007100
#> 4 Function -0.138169108 0.04320364 -3.1980896 138.9868 0.001713409
#> 5 JobControl 0.007638501 0.01972951 0.3871612 137.4752 0.699235587
#> 6 JobDemands -0.005389408 0.03704788 -0.1454714 137.6611 0.884551476
#> 7 SocialSupport 0.040056018 0.05692914 0.7036119 137.4538 0.482864689
#> OR lower.EXP upper.EXP
#> 1 1.2927393 0.0105103 159.0035655
#> 2 0.6980664 0.3050542 1.5974103
#> 3 1.0703141 0.5486967 2.0878061
#> 4 0.8709514 0.7996426 0.9486193
#> 5 1.0076677 0.9691130 1.0477563
#> 6 0.9946251 0.9243672 1.0702231
#> 7 1.0408691 0.9300526 1.1648894
Back to Examples
library(psfmi)
library(mice)
<- mice(lbp_orig, m=5, maxit=5)
imp #>
#> 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
<- complete(imp, action = "long", include = FALSE)
data_comp
library(psfmi)
<- psfmi_lr(data=data_comp, nimp=5, impvar=".imp",
pool_lr formula=Chronic ~ Gender + Smoking + Function +
+ JobDemands + SocialSupport,
JobControl p.crit = 0.157, method="D1", direction = "FW")
#> Entered at Step 1 is - Function
#>
#> Selection correctly terminated,
#> No new variables entered the model
$RR_model_final
pool_lr#> $`Final model`
#> term estimate std.error statistic df p.value OR
#> 1 (Intercept) 1.2331799 0.47595922 2.590936 115.4096 0.010806296 3.4321260
#> 2 Function -0.1399743 0.04239566 -3.301620 107.6885 0.001304682 0.8693805
#> lower.EXP upper.EXP
#> 1 1.337005 8.8103567
#> 2 0.799305 0.9455996
Back to Examples