繁体   English   中英

gtsummary 中的样式回归表

[英]Styling regression tables in gtsummary

我想以下面的格式设置回归表的样式。 这部分有点挑战是在最后的 output 中处理 NA ...我如何删除它们?

library(gtsummary)
library(stringr)

# build logistic regression model
m1 <- glm(response ~ age + stage, trial, family = binomial(link = "logit"))

tbl_m1 <- tbl_regression(m1, exponentiate = TRUE)

# Format the output inf the form OR (conf.low, conf.high)

tbl_m1$table_body <- tbl_m1$table_body %>%
  mutate(
    estimate = round(estimate, 1),
    conf.low = round(conf.low, 1),
    conf.high = round(conf.high, 1),
    #estimate = ifelse(is.na(estimate), "", estimate),
    ci = str_glue("{estimate}", " (", "{conf.low}, {conf.high}", ")") )

tbl_m1 %>%
  modify_header(label = "**Variable**",
                          ci = "**COR**") %>%
  modify_table_styling(
    columns = c("ci")) %>%
  modify_column_hide(c(estimate, p.value))

这是我会怎么做!

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.6.2'

# build logistic regression model
m1 <- glm(response ~ age + stage, trial, family = binomial(link = "logit"))

tbl_regression(m1, exponentiate = TRUE, estimate_fun = \(x) style_number(x, digits = 1)) |> 
  modify_column_merge(pattern = "{estimate} ({ci})", rows = !is.na(estimate)) |> 
  modify_header(label = "**Variable**", estimate = "**COR**") |> 
  as_kable() # convert to kable to display on StackOverflow
多变的 心率 p值
年龄 1.0 (1.0, 1.0) 0.091
T台
T1
T2 0.6 (0.2, 1.4) 0.2
T3 0.9 (0.4, 2.3) 0.9
T4 0.8 (0.3, 1.9) 0.6

创建于 2022-11-23,使用reprex v2.0.2

①如果本文未解决您的问题,请点击查看与本文相关的问题
②如果本文未解决您的问题,请向程序员专用AI小助手提问
暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM