Pooling results using multiply imputated data (MICE)

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Post Reply
johnsphoughton
Posts: 3
Joined: Mon Nov 25, 2019 4:41 pm

Pooling results using multiply imputated data (MICE)

Post by johnsphoughton »

Hi there,

I am unable to pool results using data that has been multiply imputed using the MICE package and analysed using R2MLwiN.

Code: Select all

F1 <- bmi~1+(1|id)+(1|sweepage)

model1<-with(imp1, runMLwiN(Formula = F1))

summary(pool(model1))
The final line of code produces the following error: "No glance method for objects of class mlwinfitIGLS". On a previous on this forum (https://www.cmm.bristol.ac.uk/forum/vie ... dc6467b5a5) the poster mentions difficultly getting pooled estimates when using weights, but they state that pooling worked fine without weights, however this is not the case for me.

Please can anybody help?
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: Pooling results using multiply imputated data (MICE)

Post by ChrisCharlton »

It appears that recent versions of mice have been changed so that they now rely on objects produced by the broom package instead of directly accessing the output of the coef and vcov functions. For more information see https://github.com/stefvanbuuren/mice/issues/142, https://github.com/stefvanbuuren/mice/issues/121 and https://github.com/stefvanbuuren/mice/issues/148.

The workaround would be to either use a version of mice prior to 3, or write a glance function that converts the R2MLwiN output into the expected format (see https://cran.r-project.org/web/packages ... diers.html).
johnsphoughton
Posts: 3
Joined: Mon Nov 25, 2019 4:41 pm

Re: Pooling results using multiply imputated data (MICE)

Post by johnsphoughton »

Hi Chris, thanks for your response. I have no experience writing functions so I don't think that route is possible for me. I guess I will have to look into working with an older version of mice, however I'm concerned that this may result in me not being able to impute my data using the methods I have used.
ChrisCharlton
Posts: 1348
Joined: Mon Oct 19, 2009 10:34 am

Re: Pooling results using multiply imputated data (MICE)

Post by ChrisCharlton »

Looking at their example functions (e.g. https://github.com/tidymodels/broom/blo ... -tidiers.R) the functions that you would need are something like:

Code: Select all

tidy.mlwinfitIGLS <- function(x, conf.int = FALSE, conf.level = .95, ...) {
    est <- coef(x)
    term <- names(est)
    sd <- sqrt(diag(vcov(x)))
    zscore <- est / sd
    pval <- 2 * stats::pnorm(abs(zscore), lower.tail = FALSE)
    ret <- tibble::tibble(term=term, estimate=est, std.error=sd, statistic=zscore, p.value=pval)

    if (conf.int) {
        conf <- plyr::unrowname(confint(x, level = conf.level))
        colnames(conf) <- c("conf.low", "conf.high")
        ret <- cbind(ret, conf)
    }
    ret
}

glance.mlwinfitIGLS <- function(x, ...) {
    tibble::tibble(
      logLik = stats::logLik(x),
      AIC = stats::AIC(x),
      BIC = stats::BIC(x),
      df.residual = stats::df.residual(x), 
      nobs = stats::nobs(x)
    )
}
Note that I have included AIC, BIC and df.residual to match their example and I do not know if these make sense in the multilevel context.
Post Reply