Skip to content
Prev 2013 / 5632 Next

[R-meta] Bootstrapping confidence intervals in metafor

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