The metafor Package

A Meta-Analysis Package for R

User Tools

Site Tools


tips:multiple_imputation_with_mice_and_metafor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tips:multiple_imputation_with_mice_and_metafor [2020/07/10 11:16] Wolfgang Viechtbauertips:multiple_imputation_with_mice_and_metafor [2020/12/02 17:10] Wolfgang Viechtbauer
Line 137: Line 137:
 install.packages("mice") install.packages("mice")
 library(mice) library(mice)
 +</code>
 +
 +Also, due to a recent change in the mice package (that currently breaks compatibility with the metafor package), we need to create a little helper function to make things work again.
 +
 +<code rsplus>
 +withold <- function (data, expr) {
 +  call <- match.call()
 +  analyses <- as.list(seq_len(data$m))
 +  for (i in seq_along(analyses)) {
 +    data.i <- complete(data, i)
 +    analyses[[i]] <- eval(expr = substitute(expr), envir = data.i, enclos = parent.frame())
 +    if (is.expression(analyses[[i]]))
 +      analyses[[i]] <- eval(expr = analyses[[i]], envir = data.i, enclos = parent.frame())
 +  }
 +  object <- list(call = call, call1 = data$call, nmis = data$nmis, analyses = analyses)
 +  oldClass(object) <- c("mira", "matrix")
 +  object
 +}
 </code> </code>
  
tips/multiple_imputation_with_mice_and_metafor.txt · Last modified: 2022/08/03 11:35 by Wolfgang Viechtbauer