Nelly
Nelly

Reputation: 423

Increase number of digits on presented ORs and 95% CI by tbl_regression in gtsummary package

How can I increase the number of digits on the exponentiated ORs and it corresponding 95% CI from the default 2 to say 3 digits?

library(gtsummary)
data(trial)
  glm(response ~ trt, trial, family = binomial) %>%
  tbl_regression(exponentiate = TRUE)
res <- glm(response ~ trt, trial, family = binomial) %>%
          tbl_regression(exponentiate = TRUE) %>% style_sigfig( digits = 3)
#Error in abs(x) : non-numeric argument to mathematical function

Upvotes: 5

Views: 3612

Answers (1)

akrun
akrun

Reputation: 887118

When the expoentiate is FALSE, we can modify the style_sigfig and if it is TRUE, change the digits in style_ratio as mentioned in the `?tbl_regression

estimate_fun - Function to round and format coefficient estimates. Default is style_sigfig when the coefficients are not transformed, and style_ratio when the coefficients have been exponentiated.

By default, both of them are 2.

library(gtsummary)
library(dplyr)
glm(response ~ trt, trial, family = binomial) %>%
      tbl_regression(exponentiate = TRUE, 
        estimate_fun = purrr::partial(style_ratio, digits = 3),
         pvalue_fun = purrr::partial(style_sigfig, digits = 3))

enter image description here

Upvotes: 7

Related Questions