Closed chrishanretty closed 1 year ago
@chrishanretty thanks a lot for the report and detailed example. I can reproduce the issue, but I’m not sure what’s causing it. I have spent a bunch of time trying to figure it out, but I’m not sure I’m getting any closer. I’ll keep trying, but I’m not sure when I’ll have a solution.
In the meantime, the best I can do is offer a global option to disable future
in modelsummary
. This will allow you to use furrr
for other applications, but will make modelsummary
run sequentially. Of course, you can still use the mc.cores
trick described in the documentation.
Using 1.3.0.9018 from Github:
options(modelsummary_future = FALSE)
library(modelsummary)
library(mice)
library(Amelia)
url <- 'https://vincentarelbundock.github.io/Rdatasets/csv/HistData/Guerry.csv'
dat <- read.csv(url)[, c('Clergy', 'Commerce', 'Literacy')]
dat$Clergy[sample(1:nrow(dat), 10)] <- NA
dat$Commerce[sample(1:nrow(dat), 10)] <- NA
dat$Literacy[sample(1:nrow(dat), 10)] <- NA
dat_mice <- mice(dat, m = 5, printFlag = FALSE)
dat_amelia <- amelia(dat, m = 5, p2s = 0)$imputations
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))
mod[['Mice']] <- mice::pool(mod[['Mice']])
mod[['Amelia']] <- mice::pool(mod[['Amelia']])
library(furrr)
nWorkers <- parallel::detectCores() - 1
plan(multisession, workers = nWorkers)
modelsummary(mod, output = "markdown")
Listwise deletion | Mice | Amelia | |
---|---|---|---|
(Intercept) | 80.554 | 79.365 | 79.100 |
(14.931) | (14.751) | (13.222) | |
Literacy | -0.547 | -0.541 | -0.532 |
(0.236) | (0.226) | (0.219) | |
Commerce | -0.367 | -0.373 | -0.378 |
(0.159) | (0.144) | (0.133) | |
:———— | ——————: | ———: | ———: |
Num.Obs. | 58 | 86 | 86 |
Num.Imp. | 5 | 5 | |
R2 | 0.106 | 0.122 | 0.123 |
R2 Adj. | 0.073 | 0.100 | 0.101 |
AIC | 536.9 | ||
BIC | 545.1 | ||
Log.Lik. | -264.431 | ||
F | 3.261 | ||
RMSE | 23.11 |
Modelsummary complains that it could not extracted the required information from a model of class "mipo" after a multisession plan had been initiated using
furrr
. Modelsummary can extract the required information when no plan has been started, or usingplan(sequential)
.Minimal reproducible example:
I have not yet been able to replicate this with objects of other model classes, so this may be a complicated interaction between
Amelia
andmodelsummary
.Output of
sessionInfo()
: