← 返回 Tessera
模拟9 行 × 111 KB无缺失数据 2026-09-02

forest_models

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

下载 CSV · 1 KB
数据预览6
exposuretermmodelnn_eventsperson_yearsHRCI_lowerCI_upperp_valueHR_label
bmi_categoryUnderweightUnadjusted440,04540,1995,752,8331.221.081.390.002221.22 (1.08, 1.39)
bmi_categoryUnderweightAge and sex adjusted440,04540,1995,752,8331.21.041.380.01051.20 (1.04, 1.38)
bmi_categoryUnderweightFully adjusted440,04540,1995,752,8331.181.021.370.02731.18 (1.02, 1.37)
bmi_categoryOverweightUnadjusted440,04540,1995,752,8331.531.471.65.18e-781.53 (1.47, 1.60)
bmi_categoryOverweightAge and sex adjusted440,04540,1995,752,8331.471.41.543.95e-551.47 (1.40, 1.54)
bmi_categoryOverweightFully adjusted440,04540,1995,752,8331.421.351.491.87e-411.42 (1.35, 1.49)
变量11
字符型4整数3双精度4
类型
#变量类型缺失统计
1exposureExposure represented by all rows in the table.字符型不同值 1bmi_category
2termBMI category compared with the normal-weight reference group.字符型不同值 3Underweight · Overweight · Obese
3modelAdjustment level used by the Cox model.字符型不同值 3Unadjusted · Age and sex adjusted · Fully adjusted
4nParticipants in the analytic sample.整数min 440,045q1 中位 440,045均值 440,045q3 max 440,045
5n_eventsIncident type 2 diabetes cases observed during follow-up.整数min 40,199q1 中位 40,199均值 40,199q3 max 40,199
6person_yearsTotal follow-up time, in person-years.整数min 5.8e+6q1 中位 5.8e+6均值 5.8e+6q3 max 5.8e+6
7HRkeySimulated hazard ratio for incident type 2 diabetes.双精度min 1.18q1 中位 1.47均值 1.57q3 max 2.2
8CI_lowerLower bound of the 95% confidence interval.双精度min 1.02q1 中位 1.4均值 1.46q3 max 2.09
9CI_upperUpper bound of the 95% confidence interval.双精度min 1.37q1 中位 1.54均值 1.69q3 max 2.32
10p_valueTwo-sided Wald p value derived from the estimate and standard error.双精度min 4.0e-210q1 中位 4.0e-55均值 0.00445q3 max 0.0273
11HR_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()
  )
)
URLhttps://assets.evanzhou.org/tessera/csv/forest_models.csv

Source

为森林图模型比较示例模拟的 Cox 结果。一个 BMI 分类暴露包含三个非参考水平,每个水平分别展示未校正、年龄与性别校正及完全校正模型,共 9 行。所有数值均为模拟值。

Use cases

  • 比较同一暴露在三种校正程度下的效应估计
  • 演示 assoc_coxph() 风格结果表直接传入森林图
  • 展示分类暴露的多个非参考水平
生成脚本R · 52
# 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 数出。