You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用forest.robu调整森林图参数:参考线、小数位及CI显示

robu包森林图自定义调整方案

针对你提出的三个森林图调整需求,以下是具体实现代码:

1. 将虚线参考线移至0

默认forest.robu会在汇总效应位置绘制虚线,我们可以关闭默认的汇总线,再手动添加0位置的参考线:

# 假设你的稳健模型对象为robust_model
forest.robu(robust_model, summary.line = FALSE)
# 添加0位置的灰色虚线
abline(v = 0, lty = 2, col = "gray50")

2. 调整效应量小数位数为2位

直接通过digits参数指定小数位数即可覆盖默认的3位设置:

forest.robu(robust_model, digits = 2, summary.line = FALSE)
abline(v = 0, lty = 2, col = "gray50")

3. 为单个研究添加置信区间(lb/ub)

先从模型结果中提取每个研究的效应量和置信区间,构建自定义标签后传入绘图函数:

# 提取单个研究的效应量
study_estimates <- coef(robust_model)$studies
# 提取单个研究的95%置信区间上下限
study_ci <- confint(robust_model)$studies

# 构建包含效应量+置信区间的自定义标签(保留2位小数)
custom_labels <- paste0(
  round(study_estimates, 2),
  " [", round(study_ci[, "2.5%"], 2), ", ", round(study_ci[, "97.5%"], 2), "]"
)

# 绘制森林图,使用自定义标签并关闭默认效应量文本
forest.robu(
  robust_model,
  digits = 2,
  summary.line = FALSE,
  study.labels = custom_labels,
  show.effect.size = FALSE  # 避免默认效应量与自定义标签重复
)
abline(v = 0, lty = 2, col = "gray50")

内容的提问来源于stack exchange,提问作者LucyJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 07:22:31