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
tips:multiple_imputation_with_mice_and_metafor [2020/12/13 11:45] Wolfgang Viechtbauertips:multiple_imputation_with_mice_and_metafor [2022/08/03 11:35] (current) Wolfgang Viechtbauer
Line 1: Line 1:
 ===== Multiple Imputation with the mice and metafor Packages ===== ===== Multiple Imputation with the mice and metafor Packages =====
  
-Meta-analytic data often looks like Swiss cheese -- there are lots of holes in it! For example, due to missing information, it may not be possible to compute the effect size estimates (or the corresponding sampling variances) for some of the studies. Similarly, it may not be possible to code certain moderator variables for some studies. Below, I illustrate how to use multiple imputation as a possible way to deal with the latter issue, using the [[https://cran.r-project.org/package=mice|mice]] package in combination with metafor.+A meta-analytic dataset often looks like Swiss cheese -- there are lots of holes in it! For example, due to missing information, it may not be possible to compute the effect size estimates (or the corresponding sampling variances) for some of the studies. Similarly, it may not be possible to code certain moderator variables for some studies. Below, I illustrate how to use multiple imputation as a possible way to deal with the latter issue, using the [[https://cran.r-project.org/package=mice|mice]] package in combination with metafor.
  
 ==== Data Preparation ==== ==== Data Preparation ====
Line 10: Line 10:
 dat <- dat.bangertdrowns2004 dat <- dat.bangertdrowns2004
 </code> </code>
-(I copy the dataset into 'dat', which is a bit shorter and therefore easier to type further below). We can look at the first 10 and the last 10 rows of the dataset with:+(I copy the dataset into ''dat'', which is a bit shorter and therefore easier to type further below). We can look at the first 10 and the last 10 rows of the dataset with:
 <code rsplus> <code rsplus>
 rbind(head(dat, 10), tail(dat, 10)) rbind(head(dat, 10), tail(dat, 10))
Line 80: Line 80:
 </code> </code>
 <code output> <code output>
-  1  3  +  1  3 
-41  5  2 +41  5  2
 </code> </code>
 So, for 41 studies, the data are complete, but 5 studies have one missing value, while 2 studies have three missing values. Therefore, when fitting a meta-regression model with all moderators of interest included simultaneously, only the 41 studies with complete data will be included in the analysis. So, for 41 studies, the data are complete, but 5 studies have one missing value, while 2 studies have three missing values. Therefore, when fitting a meta-regression model with all moderators of interest included simultaneously, only the 41 studies with complete data will be included in the analysis.
Line 114: Line 114:
 Model Results: Model Results:
  
-          estimate      se     zval    pval    ci.lb   ci.ub  +          estimate      se     zval    pval    ci.lb   ci.ub 
-intrcpt     0.2689  0.2154   1.2484  0.2119  -0.1533  0.6910     +intrcpt     0.2689  0.2154   1.2484  0.2119  -0.1533  0.6910 
-length      0.0072  0.0078   0.9240  0.3555  -0.0081  0.0225     +length      0.0072  0.0078   0.9240  0.3555  -0.0081  0.0225 
-wic        -0.0472  0.1097  -0.4308  0.6666  -0.2622  0.1677     +wic        -0.0472  0.1097  -0.4308  0.6666  -0.2622  0.1677 
-feedback    0.0677  0.1080   0.6265  0.5310  -0.1440  0.2793     +feedback    0.0677  0.1080   0.6265  0.5310  -0.1440  0.2793 
-info       -0.2233  0.2029  -1.1006  0.2711  -0.6210  0.1744     +info       -0.2233  0.2029  -1.1006  0.2711  -0.6210  0.1744 
-pers       -0.1137  0.1898  -0.5992  0.5490  -0.4857  0.2582     +pers       -0.1137  0.1898  -0.5992  0.5490  -0.4857  0.2582 
-imag        0.4106  0.1847   2.2233  0.0262   0.0486  0.7726  *  +imag        0.4106  0.1847   2.2233  0.0262   0.0486  0.7726 
-meta        0.2010  0.1742   1.1537  0.2486  -0.1404  0.5424    +meta        0.2010  0.1742   1.1537  0.2486  -0.1404  0.5424
  
 --- ---
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 210: Line 192:
 </code> </code>
 <code output> <code output>
-yi       vi   length      wic feedback     info     pers     imag     meta  +yi       vi   length      wic feedback     info     pers     imag     meta 
-""       ""    "pmm" "logreg" "logreg" "logreg" "logreg"       "" "logreg" +""       ""    "pmm" "logreg" "logreg" "logreg" "logreg"       "" "logreg"
  
 </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