Working together: mice and psfmi

Martijn W Heymans

2023-06-16

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.088437723 2.39728532  0.03689078 140.2898 0.970624534
#> 2        Gender -0.355692675 0.41302929 -0.86118027 148.7212 0.390525074
#> 3       Smoking  0.070911360 0.34038968  0.20832406 146.1281 0.835266034
#> 4      Function -0.135190580 0.04304434 -3.14072824 136.8765 0.002065484
#> 5    JobControl  0.008217615 0.01956697  0.41997377 147.7936 0.675114526
#> 6    JobDemands -0.001920148 0.03765469 -0.05099361 124.4584 0.959412367
#> 7 SocialSupport  0.039309546 0.05662603  0.69419571 131.5462 0.488783633
#>          OR   lower.EXP   upper.EXP
#> 1 1.0924662 0.009551675 124.9500735
#> 2 0.7006879 0.309791275   1.5848205
#> 3 1.0734861 0.547818425   2.1035662
#> 4 0.8735494 0.802271267   0.9511603
#> 5 1.0082515 0.970009356   1.0480013
#> 6 0.9980817 0.926402358   1.0753071
#> 7 1.0400924 0.929874256   1.1633747

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.222286 0.46971652  2.602178 136.8128 0.010283681 3.3949402
#> 2    Function -0.139503 0.04188283 -3.330792 133.3454 0.001120439 0.8697904
#>   lower.EXP upper.EXP
#> 1 1.3410364 8.5945611
#> 2 0.8006402 0.9449131

Back to Examples