Meta 分析森林图生成器
为系统评价和 meta 分析创建可发表的森林图,支持自定义样式和统计注释。
快速开始
from scripts.forest_plotter import ForestPlotter
plotter = ForestPlotter()
# Generate forest plot
plot = plotter.create_plot(
studies=["Study A", "Study B", "Study C"],
effect_sizes=[1.2, 0.8, 1.5],
ci_lower=[0.9, 0.5, 1.1],
ci_upper=[1.5, 1.1, 1.9],
overall_effect=1.15
)
核心功能
1. 基础森林图
fig = plotter.plot(
data=studies_df,
effect_col="HR",
ci_lower_col="CI_lower",
ci_upper_col="CI_upper",
study_col="study_name"
)
必需的数据列:
- 研究名称/标识符
- 效应量(OR、HR、RR、MD 等)
- 置信区间下限
- 置信区间上限
- 权重(可选,用于精度)
2. 统计注释
fig = plotter.plot_with_stats(
data,
heterogeneity_stats={
"I2": 45.2,
"p_value": 0.03,
"Q_statistic": 18.4
},
overall_effect={
"estimate": 1.15,
"ci": [0.98, 1.35],
"p_value": 0.08
}
)
异质性指标: | 指标 | 解释 | |--------|---------------| | I² < 25% | 低异质性 | | I² 25-50% | 中等异质性 | | I² > 50% | 高异质性 | | Q p 值 < 0.05 | 显著异质性 |
3. 亚组分析
fig = plotter.subgroup_plot(
data,
subgroup_col="treatment_type",
subgroups=["Surgery", "Radiation", "Combined"]
)
4. 自定义样式
fig = plotter.plot(
data,
style="publication",
journal="lancet", # or "nejm", "jama", "nature"
color_scheme="monochrome",
show_weights=True
)
CLI 使用
# From CSV data
python scripts/forest_plotter.py \
--input meta_analysis_data.csv \
--effect-col OR \
--output forest_plot.pdf
# With custom styling
python scripts/forest_plotter.py \
--input data.csv \
--style lancet \
--width 8 --height 10
输出格式
- PDF: 发表质量,矢量图形
- PNG: 网页/演示,300 DPI
- SVG: 可在 Illustrator/Inkscape 中编辑
- TIFF: 期刊投稿格式
参考资料
references/forest-plot-styles.md- 期刊特定格式examples/sample-plots/- 示例输出
Skill ID: 207 | Version: 1.0 | License: MIT
Scan to join WeChat group