tips:multiple_imputation_with_mice_and_metafor
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tips:multiple_imputation_with_mice_and_metafor [2020/07/10 11:16] – Wolfgang Viechtbauer | tips:multiple_imputation_with_mice_and_metafor [2020/12/13 11:48] – Wolfgang Viechtbauer | ||
---|---|---|---|
Line 137: | Line 137: | ||
install.packages(" | install.packages(" | ||
library(mice) | library(mice) | ||
+ | </ | ||
+ | |||
+ | 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, | ||
+ | analyses[[i]] <- eval(expr = substitute(expr), | ||
+ | if (is.expression(analyses[[i]])) | ||
+ | analyses[[i]] <- eval(expr = analyses[[i]], | ||
+ | } | ||
+ | object <- list(call = call, call1 = data$call, nmis = data$nmis, analyses = analyses) | ||
+ | oldClass(object) <- c(" | ||
+ | object | ||
+ | } | ||
</ | </ | ||
Line 205: | Line 223: | ||
Next, we can fit the model of interest to each of the 20 imputed datasets with: | Next, we can fit the model of interest to each of the 20 imputed datasets with: | ||
<code rsplus> | <code rsplus> | ||
- | fit <- with(imp, rma(yi, vi, mods = ~ length + wic + feedback + info + pers + imag + meta)) | + | fit <- withold(imp, rma(yi, vi, mods = ~ length + wic + feedback + info + pers + imag + meta)) |
</ | </ | ||
Line 216: | Line 234: | ||
<code output> | <code output> | ||
term estimate std.error statistic | term estimate std.error statistic | ||
- | 1 intrcpt | + | 1 intercept |
- | 2 length | + | 2 length |
- | 3 wic1 -0.0638 0.1303 -0.4897 34.5222 0.6274 | + | 3 wic1 -0.0567 0.1298 -0.4369 35.7300 0.6648 |
- | 4 feedback1 | + | 4 feedback1 |
- | 5 | + | 5 |
- | 6 | + | 6 |
- | 7 | + | 7 |
- | 8 | + | 8 |
</ | </ | ||
tips/multiple_imputation_with_mice_and_metafor.txt · Last modified: 2022/08/03 11:35 by Wolfgang Viechtbauer