Source
为森林图模型比较示例模拟的 Cox 结果。一个 BMI 分类暴露包含三个非参考水平,每个水平分别展示未校正、年龄与性别校正及完全校正模型,共 9 行。所有数值均为模拟值。
Use cases
- 比较同一暴露在三种校正程度下的效应估计
- 演示
assoc_coxph()风格结果表直接传入森林图 - 展示分类暴露的多个非参考水平
Simulated Cox results for three BMI categories under three levels of adjustment.
One row represents one BMI category under one model.
Tessera · 收录于 2026-09-02
| exposure | term | model | n | n_events | person_years | HR | CI_lower | CI_upper | p_value | HR_label |
|---|---|---|---|---|---|---|---|---|---|---|
| bmi_category | Underweight | Unadjusted | 440,045 | 40,199 | 5,752,833 | 1.22 | 1.08 | 1.39 | 0.00222 | 1.22 (1.08, 1.39) |
| bmi_category | Underweight | Age and sex adjusted | 440,045 | 40,199 | 5,752,833 | 1.2 | 1.04 | 1.38 | 0.0105 | 1.20 (1.04, 1.38) |
| bmi_category | Underweight | Fully adjusted | 440,045 | 40,199 | 5,752,833 | 1.18 | 1.02 | 1.37 | 0.0273 | 1.18 (1.02, 1.37) |
| bmi_category | Overweight | Unadjusted | 440,045 | 40,199 | 5,752,833 | 1.53 | 1.47 | 1.6 | 5.18e-78 | 1.53 (1.47, 1.60) |
| bmi_category | Overweight | Age and sex adjusted | 440,045 | 40,199 | 5,752,833 | 1.47 | 1.4 | 1.54 | 3.95e-55 | 1.47 (1.40, 1.54) |
| bmi_category | Overweight | Fully adjusted | 440,045 | 40,199 | 5,752,833 | 1.42 | 1.35 | 1.49 | 1.87e-41 | 1.42 (1.35, 1.49) |
| # | 变量 | 类型 | 缺失 | 统计 |
|---|---|---|---|---|
| 1 | exposureExposure represented by all rows in the table. | 字符型 | — | 不同值 1bmi_category |
| 2 | termBMI category compared with the normal-weight reference group. | 字符型 | — | 不同值 3Underweight · Overweight · Obese |
| 3 | modelAdjustment level used by the Cox model. | 字符型 | — | 不同值 3Unadjusted · Age and sex adjusted · Fully adjusted |
| 4 | nParticipants in the analytic sample. | 整数 | — | min 440,045q1 —中位 440,045均值 440,045q3 —max 440,045 |
| 5 | n_eventsIncident type 2 diabetes cases observed during follow-up. | 整数 | — | min 40,199q1 —中位 40,199均值 40,199q3 —max 40,199 |
| 6 | person_yearsTotal follow-up time, in person-years. | 整数 | — | min 5.8e+6q1 —中位 5.8e+6均值 5.8e+6q3 —max 5.8e+6 |
| 7 | HRkeySimulated hazard ratio for incident type 2 diabetes. | 双精度 | — | min 1.18q1 —中位 1.47均值 1.57q3 —max 2.2 |
| 8 | CI_lowerLower bound of the 95% confidence interval. | 双精度 | — | min 1.02q1 —中位 1.4均值 1.46q3 —max 2.09 |
| 9 | CI_upperUpper bound of the 95% confidence interval. | 双精度 | — | min 1.37q1 —中位 1.54均值 1.69q3 —max 2.32 |
| 10 | p_valueTwo-sided Wald p value derived from the estimate and standard error. | 双精度 | — | min 4.0e-210q1 —中位 4.0e-55均值 0.00445q3 —max 0.0273 |
| 11 | HR_labelPreformatted hazard ratio and 95% confidence interval. | 字符型 | — | 不同值 91.22 (1.08, 1.39) · 1.20 (1.04, 1.38) · 1.18 (1.02, 1.37) · 1.53 (1.47, 1.60) · 1.47 (1.40, 1.54) · 1.42 (1.35, 1.49) · 2.20 (2.09, 2.32) · 2.02 (1.92, 2.14) |
library(readr)
forest_models <- read_csv(
"https://assets.evanzhou.org/tessera/csv/forest_models.csv",
col_types = cols(
exposure = col_character(),
term = col_character(),
model = col_character(),
n = col_integer(),
n_events = col_integer(),
person_years = col_integer(),
HR = col_double(),
CI_lower = col_double(),
CI_upper = col_double(),
p_value = col_double(),
HR_label = col_character()
)
)https://assets.evanzhou.org/tessera/csv/forest_models.csv为森林图模型比较示例模拟的 Cox 结果。一个 BMI 分类暴露包含三个非参考水平,每个水平分别展示未校正、年龄与性别校正及完全校正模型,共 9 行。所有数值均为模拟值。
assoc_coxph() 风格结果表直接传入森林图# Generate the model-comparison toy data used by the forest figure recipes.
script_dir <- local({
arg <- grep("^--file=", commandArgs(trailingOnly = FALSE), value = TRUE)
path <- if (length(arg)) sub("^--file=", "", arg[[1L]]) else sys.frame(1)$ofile
dirname(normalizePath(path, mustWork = TRUE))
})
out_csv <- file.path(script_dir, "..", "csv", "forest_models.csv")
dir.create(dirname(out_csv), recursive = TRUE, showWarnings = FALSE)
terms <- data.frame(
term = c("Underweight", "Overweight", "Obese"),
n = c(440045L, 440045L, 440045L),
n_events = c(40199L, 40199L, 40199L),
person_years = c(5752833L, 5752833L, 5752833L),
hr_full = c(1.18, 1.42, 1.91),
se_full = c(0.075, 0.026, 0.029)
)
models <- data.frame(
model = c("Unadjusted", "Age and sex adjusted", "Fully adjusted"),
effect_mul = c(1.22, 1.09, 1.00),
se_mul = c(0.88, 0.94, 1.00)
)
forest_models <- do.call(rbind, lapply(seq_len(nrow(terms)), function(i) {
do.call(rbind, lapply(seq_len(nrow(models)), function(j) {
log_hr <- log(terms$hr_full[i]) * models$effect_mul[j]
se <- terms$se_full[i] * models$se_mul[j]
data.frame(
exposure = "bmi_category",
term = terms$term[i],
model = models$model[j],
n = terms$n[i],
n_events = terms$n_events[i],
person_years = terms$person_years[i],
HR = exp(log_hr),
CI_lower = exp(log_hr - 1.96 * se),
CI_upper = exp(log_hr + 1.96 * se),
p_value = 2 * pnorm(-abs(log_hr / se))
)
}))
}))
forest_models$HR <- round(forest_models$HR, 4)
forest_models$CI_lower <- round(forest_models$CI_lower, 4)
forest_models$CI_upper <- round(forest_models$CI_upper, 4)
forest_models$HR_label <- sprintf(
"%.2f (%.2f, %.2f)",
forest_models$HR, forest_models$CI_lower, forest_models$CI_upper
)
write.csv(forest_models, out_csv, row.names = FALSE)表中统计由 scripts/profile_dataset.py 于 2026-09-02 数出。