gtsummary

Unwanted extra footnote when merging columns in gtsummary table


After running the tbl_regression() function within gtsummary(), I further modified the table to merge the estimate and CI columns. However, I am getting 2 footnotes (the 1st footnote is what I'd like to keep). The 2nd appears to be the unmodified estimate column, but I can't figure out where in the code to set this to hide/NULL.

See example:

# Test data
set.seed(123)
data <- data.frame(Y = sample(x=0:1, size = 100, replace = T),
                   X1 = sample(x=1:10, size = 100, replace = T),
                   X2 = sample(x=0:1, size = 100, replace = T))

mvreg <- glm(Y ~ X1 + X2, data = data, family = binomial) %>%
  tbl_regression(pvalue_fun = function(x) style_pvalue(x, digits = 3, prepend_p = F), exponentiate = T) %>%
  modify_table_styling(
    column = estimate,
    rows = !is.na(estimate),
    cols_merge_pattern = "{estimate} ({conf.low})",
    footnote = NULL,
    footnote_abbrev = NULL) %>%
  modify_header(estimate ~ "**aOR (95% CI)**") %>%
  modify_column_hide(columns = c(conf.low)) %>%
  bold_labels() %>%
  italicize_levels() %>%
  bold_p(t = 0.05) %>%
  modify_footnote(estimate ~ "aOR = Adjusted Odds Ratio, CI = Confidence Interval")

mvreg

enter image description here


Solution

  • The handling of abbreviations in gtsummary was confusing, which is why in a recent release it's been updated. Hopefully less confusing now! You can read about it here: https://www.danieldsjoberg.com/gtsummary/news/index.html

    Here are two ways to get the notes in the table you're after. The first is using proper footnotes, and the second is using the aggregated footnotes as a source note. Hope this helps.

    library(gtsummary)
    packageVersion("gtsummary")
    #> [1] '2.1.0'
    
    set.seed(123)
    data <- data.frame(Y = sample(x=0:1, size = 100, replace = T),
                       X1 = sample(x=1:10, size = 100, replace = T),
                       X2 = sample(x=0:1, size = 100, replace = T))
    
    mvreg1 <- glm(Y ~ X1 + X2, data = data, family = binomial) |> 
      tbl_regression(pvalue_fun = function(x) style_pvalue(x, digits = 3, prepend_p = F), exponentiate = T) |> 
      modify_column_merge(
        pattern = "{estimate} ({conf.low},  {conf.high})",
        rows = !is.na(estimate)
      ) |> 
      modify_header(estimate = "**aOR (95% CI)**") |> 
      remove_abbreviation("OR = Odds Ratio") |> 
      remove_abbreviation("CI = Confidence Interval") |> 
      modify_footnote_header(
        footnote = "aOR = Adjusted Odds Ratio, CI = Confidence Interval",
        columns = estimate
      )
    

    enter image description here

    mvreg2 <- glm(Y ~ X1 + X2, data = data, family = binomial) |> 
      tbl_regression(pvalue_fun = function(x) style_pvalue(x, digits = 3, prepend_p = F), exponentiate = T) |> 
      modify_column_merge(
        pattern = "{estimate} ({conf.low},  {conf.high})",
        rows = !is.na(estimate)
      ) |> 
      modify_header(estimate = "**aOR (95% CI)**") |> 
      remove_abbreviation("OR = Odds Ratio") |> 
      modify_abbreviation("aOR = Adjusted Odds Ratio")
    

    enter image description here Created on 2025-02-20 with reprex v2.1.1