Benoit
Benoit

Reputation: 11

How to change the formatting values of the results obtained by "add_difference" function in a gtsummary table?

I'm using gtsummary package to generate great summary table of mean difference and 95% IC among paired values. However, the default output format of the mean difference and 95% IC did not include the same format and round (i.e. in my data : no digit after decimal point for the mean difference and 1 digit after decimal point for the inferior limit and no digit after decimal point for the superior limit of the 95% IC).

I try to change it using the estimate_fun= argument but i only obtained error message. Probably due to a bad syntax ? Is anyone has a solution ? :)

Example using the example table for paired data (for example, i try to obtain 1 digit round for difference and the 95%CI)(http://www.danieldsjoberg.com/gtsummary/articles/gallery.html)

trial_paired <-
  trial %>%
  select(trt, marker) %>%
  group_by(trt) %>%
  mutate(id = row_number()) %>%
  ungroup()

trial_paired %>%
  filter(!is.na(marker)) %>%
  group_by(id) %>%
  filter(n() == 2) %>%
  ungroup() %>%
  tbl_summary(by = trt, include = -id, statistic = list(all_continuous() ~ "{mean} ({sd})")) %>%
  add_difference(test = list(all_continuous() ~ "paired.t.test"), group = id, estimate_fun = list(all_continuous() ~ style_sigfig(.x, digits=1)))

Result is only : Erreur : Error in estimate_fun= argument input. Select from ‘marker’

Many thanks is anybody has a solution and sorry if the question is not so clear...

Upvotes: 1

Views: 746

Answers (1)

Daniel D. Sjoberg
Daniel D. Sjoberg

Reputation: 11719

Hello and welcome to stackoverflow!

There was a bug in the add_difference(estimate_fun=) that is now fixed in the dev version of the package on GitHub. Install the version from GitHub and use the code below.

# renv::install("ddsjoberg/gtsummary")
library(gtsummary)
#> #Uighur
packageVersion("gtsummary")
#> [1] '1.4.2.9001'

trial_paired <-
  trial %>%
  select(trt, marker) %>%
  dplyr::group_by(trt) %>%
  mutate(id = dplyr::row_number()) %>%
  dplyr::ungroup()

tbl <-
  trial_paired %>%
  dplyr::filter(!is.na(marker)) %>%
  dplyr::group_by(id) %>%
  dplyr::filter(dplyr::n() == 2) %>%
  dplyr::ungroup() %>%
  tbl_summary(by = trt, include = -id, statistic = list(all_continuous() ~ "{mean} ({sd})")) %>%
  add_difference(
    test = list(all_continuous() ~ "paired.t.test"), 
    group = id, 
    estimate_fun = marker ~ function(x) style_sigfig(x, digits = 1)
  )

enter image description here Created on 2021-07-16 by the reprex package (v2.0.0)

Upvotes: 0

Related Questions