I would like to use metafor::rma() as a smoother for ggplot. I have tried all sorts of things to get it going, but none of it seems to work. Here's a minimum (non-)working example:
# Libraries
library(metafor)
library(ggplot2)
# Some data preparation
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
# Scatterplot of the data
figure1 <- ggplot(dat, aes(y = yi, x = ablat)) + geom_point()
figure1
# Various attempts that lead to various error messages :(
figure2a <- ggplot(dat, aes(y = yi, x = ablat)) +
geom_point() + geom_smooth(method = metafor::rma())
figure2b <- ggplot(dat, aes(y = yi, x = ablat)) +
geom_point() + geom_smooth(method = metafor::rma(y = yi, vi = vi))
figure2c <- ggplot(dat, aes(y = yi, x = ablat)) +
geom_point() + geom_smooth(method = metafor::rma(y = dat$yi, vi = dat$vi))
figure2d <- ggplot(dat, aes(y = yi, x = ablat)) +
geom_point() + geom_smooth(method = metafor::rma(yi = yi, vi = vi, data = dat), formula = yi ~ ablat)
figure2e <- ggplot(dat, aes(y = yi, x = ablat)) +
geom_point() + geom_smooth(method = metafor::rma(), method.args = list(yi = dat$yi, vi = dat$vi, method = "EB"))
What am I doing wrong? Thanks