Skip to content

[R-meta] Bootstrapping confidence intervals in metafor

3 messages · Crystal La Rue, Wolfgang Viechtbauer

#
Dear Wolfgang,

I am conducting a three-level random-effects meta-analysis using metafor in R. I use Fisher's r-to-z transformed correlation coefficients and I have been advised to generate bootstrapped confidence intervals to capture a more accurate population standard error. I'm still quite new to R and am having trouble working out how to do this. Can you point me in the right direction?

Many thanks,
Crystal
11 days later
#
Dear Crystal,

This is relevant:

http://www.metafor-project.org/doku.php/tips:bootstrapping_with_ma

You just have to change boot.func() so that the appropriate model is being fitted (sounds like you are using rma.mv()) and change what is being returned (i.e., c(coef(res), vcov(res))) is probably all you need unless you want to create CIs for the variance components of the model). Here is a simple example for a non-parametric bootstrap using a three-level model:

library(metafor)
library(boot)

dat <- dat.konstantopoulos2011
res <- rma.mv(yi, vi, random = ~ 1 | district/school, data=dat)
res

boot.func <- function(dat, indices) {
   sub <- dat[indices,]
   res <- try(rma.mv(yi, vi, random = ~ 1 | district/school, data=sub), silent=TRUE)
   if (is.element("try-error", class(res))) NA else c(coef(res), vcov(res))
}

set.seed(1234)
res.boot <- boot(dat, boot.func, R=1000)
boot.ci(res.boot, index=1:2)

An interesting consideration is whether one should really do a stratified bootstrap here. This can be done with:

set.seed(1234)
res.boot <- boot(dat, boot.func, R=1000, strata=dat$district)
boot.ci(res.boot, index=1:2)

Not sure which is more appropriate here.

Best,
Wolfgang
8 days later
#
Thank you so much Wolfgang, this is really helpful!

Warm regards,
Crystal