如何编写一个包含置信区间和最后一列中的总体统计信息的gtsummary表格。

huangapple go评论76阅读模式
英文:

How to write a gtsummary with CI and overall column in last column

问题

I would like to write a summary with confidence intervals for categorical variables and an overall column at the end of the table.

However using the following code, the overall column is placed at the front:

library(gtsummary)
library(tidyverse)

trial %>%
  tbl_summary(
    by = trt,
    include = "stage") %>%
  add_overall(last = TRUE)%>%
  add_ci()

Why is the overall column at the beginning, even though I set last = TRUE?

英文:

I would like to write a summary with confidence intervals for categorical variables and an overall column at the end of the table.

However using the following code, the overall column is placed at the front:

library(gtsummary)
library(tidyverse)

trial %>%
  tbl_summary(
    by = trt,
    include = "stage") %>%
  add_overall(last = TRUE)%>% 
  add_ci()

Why is the overall column at the beginning, even though I set last = TRUE?
如何编写一个包含置信区间和最后一列中的总体统计信息的gtsummary表格。

答案1

得分: 0

以下是重新排列gtsummary表格列的解决方案:

library(gtsummary)

trial %>%
  tbl_summary(
    by = trt,
    include = "stage"
  ) %>%
  add_overall(last = TRUE) %>%
  add_ci() %>%
  modify_table_body(
    ~dplyr::relocate(.x, stat_0, ci_stat_0, .after = last_col() )
  ) %>%
  as_kable()
特征 药物 A, N = 98 95% 置信区间 药物 B, N = 102 95% 置信区间 总体, N = 200 95% 置信区间
T 分期
T1 28 (29%) 20%, 39% 25 (25%) 17%, 34% 53 (27%) 21%, 33%
T2 25 (26%) 17%, 35% 29 (28%) 20%, 38% 54 (27%) 21%, 34%
T3 22 (22%) 15%, 32% 21 (21%) 13%, 30% 43 (22%) 16%, 28%
T4 23 (23%) 16%, 33% 27 (26%) 18%, 36% 50 (25%) 19%, 32%

创建于2023-06-15,使用 reprex v2.0.2

我在这里 https://github.com/ddsjoberg/gtsummary/issues/1525 提交了一个关于gtsummary的错误报告。

英文:

See below for a solution to re-order columns in a gtsummary table.

library(gtsummary)

trial %>%
  tbl_summary(
    by = trt,
    include = "stage") %>%
  add_overall(last = TRUE) %>%
  add_ci() %>%
  modify_table_body(
    ~dplyr::relocate(.x, stat_0, ci_stat_0, .after = last_col() )
  ) %>%
  as_kable()
Characteristic Drug A, N = 98 95% CI Drug B, N = 102 95% CI Overall, N = 200 95% CI
T Stage
T1 28 (29%) 20%, 39% 25 (25%) 17%, 34% 53 (27%) 21%, 33%
T2 25 (26%) 17%, 35% 29 (28%) 20%, 38% 54 (27%) 21%, 34%
T3 22 (22%) 15%, 32% 21 (21%) 13%, 30% 43 (22%) 16%, 28%
T4 23 (23%) 16%, 33% 27 (26%) 18%, 36% 50 (25%) 19%, 32%

<sup>Created on 2023-06-15 with reprex v2.0.2</sup>

I filed a bug report with gtsummary here https://github.com/ddsjoberg/gtsummary/issues/1525

huangapple
  • 本文由 发表于 2023年6月14日 23:53:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76475431.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定