amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
447 stars 108 forks source link

Object created from pool() is empty but producing mean estimate when using summary() #676

Open evielopoo opened 1 month ago

evielopoo commented 1 month ago

Discussed in https://github.com/amices/mice/discussions/675

Originally posted by **evielopoo** October 10, 2024 This code has been running fine for months: ``` coxfit1 <- with(imp30_mids, coxph(Surv(recid, fail) ~ vet)) summary(coxfit1) coxfit1_pool <- pool(coxfit1) ``` However, starting yesterday it was returning number of observations = total number of failures, not the total number of failures + censored events. Also, my object "coxfit1_pool" is of class mipa and produces an estimate, but when I use the command view(coxfit1_pool), RStudio returns "error: object not found". Any idea what is going on here? It doesn't seem to be an issue with the imputed dataset itself (if I extract m=1 imputed dataset, it returns the correct number of observations and has no missing values).
stefvanbuuren commented 1 month ago

The mice package defines classes mira and mipo, but not mipa.

stefvanbuuren commented 1 month ago

Also, try View(), not view. The devil is in the details.

evielopoo commented 1 month ago

Sorry for the typo, the class is indeed mipo. However, whether I use View() or view() the object returns the same error, attached in a screenshot.

Screen Shot 2024-10-11 at 11 28 05 AM

My model still runs fine, and I can see that the object is not actually empty if I use str(coxfit1_pool).

stefvanbuuren commented 6 days ago

I am not able to reproduce your problem.

library(mice, warn.conflicts = FALSE)
library(survival)

set.seed(1)
data <- survival::lung
data$age[rbinom(nrow(data), size = 1, prob = 0.2) == 1] <- NA
data$sex[rbinom(nrow(data), size = 1, prob = 0.2) == 1] <- NA
data$ph.ecog[rbinom(nrow(data), size = 1, prob = 0.2) == 1] <- NA

imp <- mice(data, print = FALSE)
fit <- with(imp, coxph(Surv(time, status) ~ age))
summary(pool(fit))
#>   term  estimate  std.error statistic       df   p.value
#> 1  age 0.0200698 0.01067183  1.880633 38.41092 0.0676197

Created on 2024-11-21 with reprex v2.1.1

Can you try this code on your system? And, if that works, adapt it to your data?