Working together: mice and psfmi

Introduction

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.

Installing the psfmi and mice packages

You can install the released version of psfmi with:

install.packages("psfmi")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("mwheymans/psfmi")

You can install the released version of mice with:

install.packages("mice")

Examples

mice and psfmi for pooling logistic regression models


  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.1969517386 2.44029888  0.08070804 117.55156 0.935811391
#> 2        Gender -0.3805856345 0.41415200 -0.91895159 146.75220 0.359628848
#> 3       Smoking  0.0845463928 0.33966342  0.24891227 148.70159 0.803772107
#> 4      Function -0.1374798284 0.04319862 -3.18250481 139.48225 0.001800351
#> 5    JobControl  0.0041118444 0.01971262  0.20858942 127.20214 0.835102412
#> 6    JobDemands -0.0006738983 0.04015484 -0.01678249  62.74426 0.986663390
#> 7 SocialSupport  0.0446974652 0.05779249  0.77341301 116.79890 0.440840494
#>          OR  lower.EXP   upper.EXP
#> 1 1.2176853 0.00969936 152.8716779
#> 2 0.6834610 0.30147805   1.5494295
#> 3 1.0882233 0.55619071   2.1291798
#> 4 0.8715519 0.80020399   0.9492614
#> 5 1.0041203 0.96570654   1.0440621
#> 6 0.9993263 0.92226438   1.0828274
#> 7 1.0457114 0.93261800   1.1725191

Back to Examples

mice and psfmi for selecting logistic regression models


  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.2214174 0.46033589  2.653318 151.7147 0.0088191936 3.3919922
#> 2    Function -0.1398556 0.04104929 -3.407016 151.3840 0.0008414066 0.8694838
#>   lower.EXP upper.EXP
#> 1 1.3660466 8.4225613
#> 2 0.8017495 0.9429405

Back to Examples