Pan Qing
Pan Qing

Reputation: 129

How to generate t-value, F-value or Chi-square in the summary table using R package "gtsummary"?

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"

Upvotes: 5

Views: 2290

Answers (2)

yadevi
yadevi

Reputation: 1

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

Upvotes: 0

Daniel D. Sjoberg
Daniel D. Sjoberg

Reputation: 11774

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)

Upvotes: 6

Related Questions