5

I am working on creating summary table using the excellent R package "gtsummary", it really help me a lot in efficiently and accurately generating summary tables. But I wonder whether some of the statistics such as t-value, F-value, and Chi-square could be automatically generated just like the p-value?

library(gtsummary)

add_p_ex1 <-
  trial[c("age", "grade", "response", "trt")] %>%
  tbl_summary(by = trt) %>%
  add_p()

Here is the summary table generated using "gtsummary"

Pan Qing
  • 129
  • 6

2 Answers2

6

UPDATED 2021-07-23

The test statistics are returned in a column called statistic. The column, however, is hidden by default from the output. You can add the test statistics to the table by assigning a column header (which will auto unhide the column). Example below!

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

tbl <-
  trial %>%
  select(age, grade, response, trt) %>%
  tbl_summary(by = trt) %>%
  add_p(test = all_continuous() ~ "t.test") %>%
  # add a header to the statistic column, which is hidden by default
  # adding the header will also unhide the column
  modify_header(statistic ~ "**Test Statistic**") %>%
  modify_fmt_fun(statistic ~ style_sigfig)

enter image description here Created on 2021-07-23 by the reprex package (v2.0.0)

Daniel D. Sjoberg
  • 8,820
  • 2
  • 12
  • 28
  • Professor Sjoberg, thank you very much for the detail replay. The answer help me a lot. – Pan Qing May 05 '20 at 16:57
  • Professor Sjoberg, I have work out the t-value and chi-square in the summary table follow your valuable advice. Now when I move on, I came up with another puzzle with the "digits setting" in the summary table, as bellow. https://stackoverflow.com/questions/61638996/why-the-function-round-does-not-work-on-the-digits-of-p-value-and-how-to-adju – Pan Qing May 06 '20 at 15:35
0

modify_fmt_fun(statistic ~ style_sigfig) this part of the code doesn't work. however the rest gives the output with 4 d

yadevi
  • 1