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

Next revision
Previous revision
Next revisionBoth sides next revision
tips:multiple_imputation_with_mice_and_metafor [2019/10/09 12:46] – external edit 127.0.0.1tips:multiple_imputation_with_mice_and_metafor [2020/07/10 11:16] Wolfgang Viechtbauer
Line 133: Line 133:
 One way of dealing with missing data is to make use of imputation techniques. The advantage of using [[wp>Imputation_(statistics)#Multiple_imputation|multiple imputation]] is that we not only impute once (and then pretend that the imputed values are free of any uncertainty), but multiple times from appropriate distributions, so that several imputed datasets are generated. The same analysis is then applied to each dataset and the results are pooled, taking into consideration not only the uncertainty in each fitted model, but also across models. One way of dealing with missing data is to make use of imputation techniques. The advantage of using [[wp>Imputation_(statistics)#Multiple_imputation|multiple imputation]] is that we not only impute once (and then pretend that the imputed values are free of any uncertainty), but multiple times from appropriate distributions, so that several imputed datasets are generated. The same analysis is then applied to each dataset and the results are pooled, taking into consideration not only the uncertainty in each fitted model, but also across models.
  
-The mice package allows us to automate this process and can be used in combination with the metafor package. First, we install and load the mice package and then evaluate some code from the metafor package that generates two helper functions we need so that mice and metafor can interact as necessary:+The [[https://cran.r-project.org/package=mice|mice]] package allows us to automate this process and can be used in combination with the metafor package. First, we install and load the mice package:
 <code rsplus> <code rsplus>
 install.packages("mice") install.packages("mice")
 library(mice) library(mice)
-eval(metafor:::.mice) 
 </code> </code>
  
Line 209: Line 208:
 </code> </code>
  
-And finally, we can pool the results with:+And finally, we can pool (and round) the results with:
 <code rsplus> <code rsplus>
-pool <- pool(fit) +pool <- summary(pool(fit)
-round(summary(pool), 4)+pool[-1] <- round(pool[-1]digits=4) 
 +pool
 </code> </code>
 <code output> <code output>
-          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.1089 +1   intrcpt   0.3970    0.2418    1.6417 37.3121  0.1091 
-length      0.0132    0.0088    1.5052 37.1180  0.1405 +2    length   0.0132    0.0088    1.5052 37.1180  0.1407 
-wic1       -0.0638    0.1303   -0.4897 34.5222  0.6271 +3      wic1  -0.0638    0.1303   -0.4897 34.5222  0.6274 
-feedback1  -0.0066    0.1209   -0.0543 34.3060  0.9570 +feedback1  -0.0066    0.1209   -0.0543 34.3060  0.9570 
-info1      -0.3133    0.2307   -1.3583 37.5709  0.1824 +5     info1  -0.3133    0.2307   -1.3583 37.5709  0.1825 
-pers1      -0.3233    0.1937   -1.6689 37.5493  0.1034 +6     pers1  -0.3233    0.1937   -1.6689 37.5493  0.1035 
-imag1       0.2117    0.2096    1.0099 38.0212  0.3189 +7     imag1   0.2117    0.2096    1.0099 38.0212  0.3189 
-meta1       0.4623    0.1739    2.6583 37.4993  0.0114+8     meta1   0.4623    0.1739    2.6583 37.4993  0.0115
 </code> </code>
  
 For easier comparison, let's look at the coefficient table based on the complete case analysis obtained earlier: For easier comparison, let's look at the coefficient table based on the complete case analysis obtained earlier:
 <code rsplus> <code rsplus>
-round(coef(summary(res)), 4)+round(coef(summary(res)), digits=4)
 </code> </code>
 <code output> <code output>
-          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
 </code> </code>
  
tips/multiple_imputation_with_mice_and_metafor.txt · Last modified: 2022/08/03 11:35 by Wolfgang Viechtbauer