mice and miceafter for Regression modelling"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(miceafter)
library(mice)
library(magrittr)
library(dplyr)

Installing the miceafter and mice packages

You can install the development version from GitHub with:

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

You can install mice with:

install.packages("mice")

Examples

mice and miceafter for pooling logistic regression models

lbp_orig is a dataset that is part of the miceafter package with missing values. So we first impute them with the mice function. Than we use the mids2milist function to turn a mids object, as a result of using mice, into a milist object with multiply imputed datasets. Than we use the with function to apply repeated logistic regression analyses. With the pool_glm function we obtain the results for the pooled model.

  library(mice)
  library(miceafter)

  imp <- mice(lbp_orig, m=5, maxit=5, printFlag = FALSE) 

  dat_imp <- mids2milist(imp)

  ra <- with(dat_imp, expr = glm(Chronic ~ factor(Carrying) + Gender + Smoking + 
                      Function + JobControl + JobDemands + SocialSupport, 
                      family = binomial))

  poolm <- pool_glm(ra, method="D1")
  poolm$pmodel
  poolm$pmultiparm

Back to [Examples]

mice and miceafter for pooling linear regression models

The lbp_orig is a dataset that is part of the miceafter package with missing values. So we first impute them with the mice function. Than we use the mids2milist function to turn a mids object, as a result of using mice, into a milist object with multiply imputed datasets. Than we use the with function to apply repeated linear regression analyses. With the pool_glm function we obtain the results for the pooled model.

  library(mice)
  library(miceafter)

  imp <- mice(lbp_orig, m=5, maxit=5, printFlag = FALSE) 

  dat_imp <- mids2milist(imp)

  ra <- with(dat_imp, expr = glm(Pain ~ factor(Carrying) + Gender + Smoking + 
                      Function + JobControl + JobDemands + SocialSupport))

  poolm <- pool_glm(ra, method="D1")
  poolm$pmodel
  poolm$pmultiparm

Back to [Examples]

mice and miceafter for selecting logistic regression models

We follow the same procedure as the first example but also apply model selection here.

  library(mice)
  library(miceafter)

  imp <- mice(lbp_orig, m=5, maxit=5, printFlag = FALSE) 

  dat_imp <- mids2milist(imp)

  ra <- with(dat_imp, expr = glm(Chronic ~ factor(Carrying) + Gender + Smoking + 
                      Function + JobControl + JobDemands + SocialSupport, 
                      family = binomial))

  poolm <- pool_glm(ra, method="D1", p.crit = 0.15, direction = "BW")
  poolm$pmodel
  poolm$pmultiparm

Back to [Examples]

mice and miceafter for selecting linear regression models

We follow the same procedure as the second example but also apply model selection here.

  library(mice)
  library(miceafter)

  imp <- mice(lbp_orig, m=5, maxit=5, printFlag = FALSE) 

  dat_imp <- mids2milist(imp)

  ra <- with(dat_imp, expr = glm(Pain ~ factor(Carrying) + Gender + Smoking + 
                      Function + JobControl + JobDemands + SocialSupport))

  poolm <- pool_glm(ra, method="D1", p.crit = 0.15, direction = "BW")
  poolm$pmodel
  poolm$pmultiparm

Back to [Examples]



Try the miceafter package in your browser

Any scripts or data that you put into this service are public.

miceafter documentation built on Oct. 2, 2022, 5:08 p.m.