rgtsummary

tbl_summary add column with test statistic


Consider the tbl_summary example:

trial |>
  tbl_summary(by = trt, include = c(age, grade)) |>
  add_p()    

How can I add a column with the test statistic the p-value refers to?

In my field it is common to report the test statistic in the text, followed by the p-value.


Solution

  • By default the test statistics are hidden, and you can unhide them using modify_column_unhide().

    library(gtsummary)
    packageVersion("gtsummary")
    
    trial |>
      tbl_summary(by = trt, include = c(age, grade)) |>
      add_p() |> 
      separate_p_footnotes() |> 
      modify_column_unhide("statistic") |> 
      remove_footnote_header(columns = "statistic")
    

    enter image description here