'Adding significant superscript according to post-hoc test

I'm trying to make this table using tbl_summary(). Is it possible to include the superscripts for post hoc test for each group? The post hoc test of interest in this case is TukeyHSD. enter image description here

Thank you!



Solution 1:[1]

After you calculate the p-values, you just need to map the p-values to the location on the tbl_summary(). The rows can be identified by the variable name and the row type. For example, the first row in the table could be identified with variable == "sptf_day" & row_type == "label" (you can inspect the underlying data frame by printing x$table_body). Then you need to identify the column where the footnote will be placed. Use the show_header_names() function to print the underlying column names along with the label.

Once you have those two pieces of information, you can add a footnote like this.

df %>%
  tbl_summary() %>%
  modify_table_styling(
    columns = stat_1, 
    rows = variable == "sptf_day" & row_type == "label",
    footnote = "add your footnote text here" 
  )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel D. Sjoberg