首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将metafor::rma与geom_smooth一起使用?

将metafor::rma与geom_smooth一起使用?
EN

Stack Overflow用户
提问于 2020-03-30 08:43:10
回答 1查看 109关注 0票数 0

我想使用metafor::rma()作为ggplot的平滑器。我尝试了各种方法来让它继续运行,但似乎都不起作用。下面是一个最小的(非)工作示例:

代码语言:javascript
运行
复制
# 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"))

我做错了什么?谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-04-01 02:07:32

我曾短暂地尝试过让它与geom_smooth()一起工作,但我并不是一个ggplot2重度用户,因此没有成功。但正如@Tjebo建议的那样,您可以使用predict()计算预测值,然后使用geom_line()geom_ribbon()添加元素。下面是一个示例:

代码语言:javascript
运行
复制
library(metafor)
library(ggplot2)

dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
res <- rma(yi, vi, mods = ~ ablat, data=dat)
pred <- as.data.frame(predict(res, newmods = seq(0,60,by=1), addx=TRUE))
names(pred)[8] <- "ablat"

ggplot(dat, aes(x = ablat)) +
   geom_point(aes(y = yi)) +
   geom_line(data = pred, aes(x = ablat, y = pred)) +
   geom_ribbon(data = pred, aes(ymin = ci.lb, ymax = ci.ub), fill = "blue", alpha = 0.2)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60922582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档