4

Does anyone know if it is possible exclude some p-values from the a summary table (tbl_summary() with add_p())?

Also, can we change the footnote about the tests used?

library(gtsummary)

mtcars %>%
tbl_summary(by = am) %>%
add_p()

2 Answers2

4

These are great customization questions and the answers are YES!!

First of all, you can use the include = argument to the add_p() function, with a character vector of variables you want to include (or exclude using -), or any tidyselect helper (i.e. starts_with()), to select which p-values to include in the table.

Next, I've provided an example using the arguments from {gt} package on how to modify the default footnote listing tests. Another example can be seen in the {gtsummary} gallery of tables.

Good luck, hope this helps!

library(gtsummary)
library(dplyr, warn.conflicts = F)
library(gt)

trial %>% 
  select(trt, stage, age, grade) %>% 
  tbl_summary(by = trt) %>% 
  add_p(
    include = c(-age) #Can use any tidyselect helpers/select syntax to specify which p-vals
  ) %>% 
  as_gt(include = -tab_footnote) %>%  # if using gt, can exclude footnotes this way 
  tab_footnote( # and can modify/add footnotes this way
    footnote = "Tests used are...",
    locations = cells_column_labels(columns = vars(p.value))
  )

enter image description here

3

An other way is to directly tweek the list:

plouf <- mtcars %>%
  tbl_summary(by = am) %>%
  add_p()
plouf$table_body[1,"p.value"] <- NA
plouf$table_header[6,"footnote"] <- "my personal statistic test"
plouf

enter image description here

denis
  • 5,580
  • 1
  • 13
  • 40