Table including between-group p value comparison for 3+ groups using ANOVA

Viewed 545

Firstly - love gtsummary! It's revolutionised how I do stats for all my papers and made me dive fully into R.

Wondering if there is a way to do between-group comparisons using ANOVA with gtsummary?

Here's an example: enter image description here

We have 3 groups here and 5 features. I can generate this table using tbl_summary and add_p. That gives me the overall p value for group differences per features, but I then need to manually go in and add those signifiers (* , † and ‡) which represent significant between group difference (Group 1 vs 2; Group 1 vs 3 etc...).

I have to use SPSS for this, for which I use the following SPSS code to do ANOVA with post-hoc Bonferroni correction.

ONEWAY A B C D E BY group_factor
  /STATISTICS DESCRIPTIVES
  /MISSING ANALYSIS
  /POSTHOC=BONFERRONI ALPHA(0.05).

The output of SPSS here is a basically a table that generates for each feature the P value when comparing group 1 vs 2, group 2 vs 3 etc...

I then have to manually read for significant between-group results and then add signifiers to the original gtsummary table.

Is there a way this could be automated or incorporated into gtsummary? It will save me literally hours of manual tedious work!

1 Answers

gtsummary tables are highly customizable, and you can add these footnotes. I've included an example below where the pairwise comparisons are visually inspected and the footnotes manually added. But you could wrap this up in a function and apply the footnotes programmatically.

library(gtsummary)
library(tidyverse)
packageVersion("gtsummary")
#> [1] '1.5.0'
theme_gtsummary_mean_sd()

# build table with one-way ANOVA results
tbl1 <- 
  trial %>%
  select(marker, grade) %>%
  tbl_summary(by = grade, missing = "no") %>%
  add_p()

enter image description here

# calculate pairwise comparison p-values
pairwise.t.test(trial[["marker"]], trial[["grade"]], p.adj = "none")
#> 
#>  Pairwise comparisons using t tests with pooled SD 
#> 
#> data:  trial[["marker"]] and trial[["grade"]] 
#> 
#>     I    II  
#> II  0.01 -   
#> III 0.64 0.04
#> 
#> P value adjustment method: none

# add footnotes for sig comparisons
tbl2 <-
  tbl1 %>%
  modify_table_styling(
    column = stat_1,
    rows = variable == "marker",
    footnote = "Mean significantly different from Grade II"
  ) %>%
  modify_table_styling(
    column = stat_2,
    rows = variable == "marker",
    footnote = "Mean significantly different from Grade III"
  ) %>%
  modify_table_styling(
    column = stat_3,
    rows = variable == "marker",
    footnote = "Mean significantly different from Grade II"
  )

enter image description here Created on 2021-11-04 by the reprex package (v2.0.1)

Related