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()
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)
Created on 2021-07-23 by the reprex package (v2.0.0)