### copy data into 'dat' and examine data
dat <- dat.bourassa1996
head(dat, 10)
if (FALSE) {
### load metafor package
library(metafor)
### calculate log(OR) and corresponding sampling variance with 1/2 correction
dat <- escalc(measure="OR", ai=lh.le, bi=lh.re, ci=rh.le, di=rh.re, data=dat, add=1/2, to="all")
head(dat, 10)
### overall association between handedness and eyedness
res <- rma(yi, vi, data=dat, subset=sex=="combined")
res
predict(res, transf=exp, digits=2)
### multilevel model to account for heterogeneity at the study and sample levels
res <- rma.mv(yi, vi, random = ~ 1 | study/sample, data=dat, subset=sex=="combined")
res
predict(res, transf=exp, digits=2)
### restructure the dataset to keep only the male/female data when it is reported
### separately and the combined data when this is the only data reported
dat <- lapply(split(dat, dat$sample), function(x) {
if (nrow(x) == 3L) {
x[-which(x$sex == "combined"),]
} else {
x
}
})
dat <- do.call(rbind, dat)
rownames(dat) <- NULL
dat
### multilevel model to account for heterogeneity at the study, sample, and subgroup levels
res <- rma.mv(yi, vi, random = ~ 1 | study/sample/sex, data=dat)
res
predict(res, transf=exp, digits=2)
}
Run the code above in your browser using DataLab