I calculate the effectiveness of vaccination (VE), which I get as 1 - HR from the cox model. I use the tbl_regression function to create a table with VE and corresponding confidence intervals.
Using this code, I get the confidence intervals limits in the table in the opposite order than I would like (VE (upper CI - lower CI)):
tbl_regression(m1_cox, estimate_fun = function(x) {round(1 - exp(x) , 2)}
Is there any way to display the limits of the CI in the correct order (VE (lower CI - upper CI))?
You can! See example below
library(gtsummary)
library(survival)
packageVersion("gtsummary")
#> [1] '1.7.0'
tbl <-
coxph(Surv(time, status) ~ age + sex, data = lung) |>
tbl_regression(estimate_fun = function(x) style_ratio(1 - exp(x), 2)) |>
modify_column_hide(ci) |> # hide the current confidence interval
modify_column_merge(pattern = "{conf.high}, {conf.low}") |> # re-construct a CI reversing the order
modify_header( # update the headers to match the new estimates
conf.high = "**95% CI**",
estimate = "**VE**"
) |>
modify_footnote( # update the abbreviation footnotes
estimate = "VE = Vaccine Effectiveness",
conf.high = "CI = Confidence Interval",
abbreviation = TRUE
)
Created on 2023-03-14 with reprex v2.0.2