Nelly
Nelly

Reputation: 423

Change default variable value display in tbl_regression/tbl_uvregression and tbl_summary? #gtsummary

After running a model e.g. cox model, I would like to change the default variable values on the table rows e.g. instead of the default Grade variable values: "I", "II", "III", I would like to have "A", "B", "C" respectively displayed instead.

  1. How can I do that for tbl_regression and tbl_uvregression results?
  2. How would one also do that with the tbl_summary results?

Here is an example code:

coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%
tbl_regression(exponentiate = TRUE)

Thank you!

Upvotes: 1

Views: 1022

Answers (1)

Daniel D. Sjoberg
Daniel D. Sjoberg

Reputation: 11754

The method to make this change is the same for all gtsummary tables: update your data before you pipe it into the summarizing table.

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.3.6'

tbl <-
  trial %>%
  select(grade) %>%
  # update grade levels
  mutate(grade = factor(grade, labels = c("A", "B", "C"))) %>%
  tbl_summary()

enter image description here

Created on 2021-01-14 by the reprex package (v0.3.0)

Upvotes: 2

Related Questions