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 revision
Previous revision
Next revisionBoth sides next revision
tips:multiple_imputation_with_mice_and_metafor [2020/12/13 11:45] Wolfgang Viechtbauertips:multiple_imputation_with_mice_and_metafor [2021/03/29 20:52] 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>
  
Line 223: Line 205:
 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 <- withold(imp, rma(yi, vi, mods = ~ length + wic + feedback + info + pers + imag + meta))+fit <- with(imp, rma(yi, vi, mods = ~ length + wic + feedback + info + pers + imag + meta))
 </code> </code>
  
Line 234: Line 216:
 <code output> <code output>
        term estimate std.error statistic      df p.value        term estimate std.error statistic      df p.value
-  intrcpt   0.3970    0.2418    1.6417 37.3121  0.1091 +intercept   0.3819    0.2415    1.5814 36.6335  0.1224 
-2    length   0.0132    0.0088    1.5052 37.1180  0.1407 +2    length   0.0135    0.0088    1.5353 36.6917  0.1333 
-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  -0.0066    0.1209   -0.0543 34.3060  0.9570 +4 feedback1   0.0007    0.1222    0.0061 33.6335  0.9952 
-5     info1  -0.3133    0.2307   -1.3583 37.5709  0.1825 +5     info1  -0.3099    0.2280   -1.3594 37.1289  0.1822 
-6     pers1  -0.3233    0.1937   -1.6689 37.5493  0.1035 +6     pers1  -0.3096    0.1972   -1.5701 35.2466  0.1253 
-7     imag1   0.2117    0.2096    1.0099 38.0212  0.3189 +7     imag1   0.2015    0.2111    0.9545 37.4837  0.3459 
-8     meta1   0.4623    0.1739    2.6583 37.4993  0.0115+8     meta1   0.4482    0.1778    2.5204 35.7384  0.0163
 </code> </code>
  
tips/multiple_imputation_with_mice_and_metafor.txt · Last modified: 2022/08/03 11:35 by Wolfgang Viechtbauer