guido-s / meta

Official Git repository of R package meta
http://cran.r-project.org/web/packages/meta/index.html
GNU General Public License v2.0
82 stars 32 forks source link

Conversion/Import of metafor::rma objects for usage with meta::forest() #20

Closed SBCV closed 4 years ago

SBCV commented 4 years ago

I've (already) conducted a meta analysis with the metafor package. Now, I've discovered the meta package and realized that the meta::forest() function creates way better forest plots than the corresponding function in the metafor package.

I've read that the meta package uses the metafor package internally. So, I'm wondering, if there is a convenient way to cast the metafor::rma objects to objects of type meta::meta (which are required as input of meta::forest())?

Best regards, Sebastian

guido-s commented 4 years ago

Hi Sebastian,

You can use an rma object as input to metagen(). E.g.,

library(meta)
data(Olkin95)
dat <- subset(Olkin95, year < 1970)

m4 <- metafor::rma(ai = event.e, bi = n.e - event.e,
                   ci = event.c, di = n.c - event.c,
                   measure = "OR", data = dat, slab = author)

m <- metagen(m4$yi, sqrt(m4$vi), studlab = m4$slab, sm = m4$measure,
             comb.fixed = m4$method == "FE", comb.random = m4$method != "FE",
             method.tau = ifelse(m4$method == "FE", "DL", m4$method),
             hakn = m4$test == "hakn")

# Same results
m4
print(summary(m), backtransf = FALSE, digits.Q = 4)

# Forest plot
forest(m, leftcols = "studlab", leftlab = "Author", hetlab = "")

Note, I2 values are slightly different as meta and metafor use different calculation methods (see https://stat.ethz.ch/pipermail/r-sig-meta-analysis/2019-May/001544.html).

Best wishes, Guido

SBCV commented 4 years ago

Thank you for the fast response!