Warning: The code in this vignette relies on tidy and glance methods which were recently added to the mice package. As of 2020-06-12, they were only available in the development version of the package (>3.9.0). The most recent version of mice can be installed by calling: remotes::install_github('stefvanbuuren/mice')
modelsummary can pool and display analyses on several datasets imputed using the mice or Amelia packages. This code illustrates how:
library(mice) library(Amelia) library(modelsummary) # Download data from `Rdatasets` url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv' dat <- read.csv(url)[, c('Clergy', 'Commerce', 'Literacy')] # Insert missing values dat$Clergy[sample(1:nrow(dat), 10)] <- NA dat$Commerce[sample(1:nrow(dat), 10)] <- NA dat$Literacy[sample(1:nrow(dat), 10)] <- NA # Impute with `mice` and `Amelia` dat_mice <- mice(dat, m = 5, printFlag = FALSE) dat_amelia <- amelia(dat, m = 5, p2s = 0)$imputations # Estimate models mod <- list() mod[['Listwise deletion']] <- lm(Clergy ~ Literacy + Commerce, dat) mod[['Mice']] <- with(dat_mice, lm(Clergy ~ Literacy + Commerce)) mod[['Amelia']] <- lapply(dat_amelia, function(x) lm(Clergy ~ Literacy + Commerce, x)) # Pool results mod[['Mice']] <- mice::pool(mod[['Mice']]) mod[['Amelia']] <- mice::pool(mod[['Amelia']]) # Summarize modelsummary(mod)
| Listwise deletion | Mice | Amelia | |
|---|---|---|---|
| (Intercept) | 72.736 | 68.866 | 64.108 |
| (14.116) | (12.693) | (14.273) | |
| Literacy | -0.489 | -0.381 | -0.353 |
| (0.223) | (0.193) | (0.197) | |
| Commerce | -0.226 | -0.230 | -0.162 |
| (0.157) | (0.160) | (0.180) | |
| Num.Obs. | 57 | 86 | 86 |
| Num.Imp. | 5 | 5 | |
| R2 | 0.084 | 0.059 | 0.050 |
| R2 Adj. | 0.050 | 0.035 | 0.025 |
| AIC | 529.1 | ||
| BIC | 537.3 | ||
| Log.Lik. | -260.545 | ||
| F | 2.478 |