Changing () to [] for confidence interval in gtsummary table

261 Views Asked by At

I am making my demographics table using gtsummary. I want the confidence interval in my table to appear between [] not (). For example,

  trial %>%
    select(response, grade) %>%
    tbl_summary(statistic = all_categorical() ~ "{p}%",
                missing = "no") %>%
    modify_footnote(everything() ~ NA) %>%
    add_ci()

This produces:

enter image description here

I appreciate your help

2

There are 2 best solutions below

0
Sajin Kang On

Sorry I made a mistake I want the IQR to appear between []

Here is an example.

library(gtsummary)
data=colon
tbl_summary(data=colon, by=rx, missing='no')

enter image description here

for.example nodes 2.0 (1.0, 5.0) to 2.0 [1.0, 5.0]

0
PTS390 On

at least about the CI, you can add this to your code:

trial %>%
  select(response, grade) %>%
  tbl_summary(statistic = all_categorical() ~ "{p}%",
              missing = "no") %>%
  modify_footnote(everything() ~ NA) %>%
  
  add_ci(pattern = "{stat} [{ci}]") 

enter image description here

As for the IQR, here is an example

  trial %>%
    select(age) %>%
    tbl_summary(
                statistic =  all_continuous() ~ "{mean} [{IQR}]",
                missing = "no") 

enter image description here