### copy data into 'dat' and examine data
dat <- dat.tannersmith2016
head(dat)
if (FALSE) {
### load metafor package
library(metafor)
### compute mean age variables within studies
dat$aget1 <- ave(dat$aget1, dat$studyid)
dat$aget2 <- ave(dat$aget2, dat$studyid)
### construct an effect size identifier variable
dat$esid <- 1:nrow(dat)
### construct an approximate var-cov matrix assuming a correlation of 0.8
### for multiple coefficients arising from the same study
V <- vcalc(vi, cluster=studyid, obs=esid, rho=0.8, data=dat)
### fit a multivariate random-effects model using the approximate var-cov matrix V
res <- rma.mv(yi, V, random = ~ esid | studyid, data=dat)
res
### use cluster-robust inference methods
robust(res, cluster=studyid, clubSandwich=TRUE)
### note: the results obtained above and below are slightly different compared
### to those given by Tanner-Smith et al. (2016) since the approach illustrated
### here makes use a multivariate random-effects model for the 'working model'
### before applying the cluster-robust inference methods, while the results given
### in the paper are based on a somewhat simpler working model
### examine the main effects of the age variables
res <- rma.mv(yi, V, mods = ~ aget1 + aget2,
random = ~ 1 | studyid/esid, data=dat)
robust(res, cluster=studyid, clubSandwich=TRUE)
### also examine their interaction
res <- rma.mv(yi, V, mods = ~ aget1 * aget2,
random = ~ 1 | studyid/esid, data=dat)
robust(res, cluster=studyid, clubSandwich=TRUE)
### add the sexmix factor to the model
res <- rma.mv(yi, V, mods = ~ aget1 * aget2 + sexmix,
random = ~ 1 | studyid/esid, data=dat)
robust(res, cluster=studyid, clubSandwich=TRUE)
}
Run the code above in your browser using DataLab