When making a regression table using {gtsummary},
p-value can be added through add_glance_table(p.value)
:
library(gtsumary)
trial %>%
na.exclude() %>%
lm(ttdeath ~ age marker response,.) %>%
tbl_regression() %>%
add_glance_table(p.value)
I would like to add significance star(s) to the p-value in glance table.
I have tried add_significance_stars()
, but it only replaces the original p-values created by tbl_regression()
to the stars.
Is there any way I can put significance stars on p-values in the glance table?
Edit: I would like to apologize my initial question which lacked information and clarity. Edited for more information.
CodePudding user response:
The add_significance_stars()
function can add stars to the model covariate p-values. We can add a function to format the model p-value with significance stars as well. Example below
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.0'
# write a function to round p-values and add stars
style_pvalue_stars <- function(x) {
dplyr::case_when(
x < 0.001 ~ paste0(style_pvalue(x), "***"),
x < 0.01 ~ paste0(style_pvalue(x), "**"),
x < 0.05 ~ paste0(style_pvalue(x), "*"),
TRUE ~ style_pvalue(x)
)
}
style_pvalue_stars(c(0.0001, 0.04, 0.50))
#> [1] "<0.001***" "0.040*" "0.5"
tbl <-
lm(ttdeath ~ age marker response, trial) %>%
tbl_regression() %>%
# add significance stars to the covariate p-values
add_significance_stars(pattern = "{p.value}{stars}",
hide_ci = FALSE, hide_p = FALSE) %>%
add_glance_table(p.value) %>%
# add stars to the model p-value
modify_fmt_fun(
update = estimate ~ style_pvalue_stars,
rows = row_type == "glance_statistic" & label == "p-value"
)
Created on 2022-01-01 by the reprex package (v2.0.1)
Happy Programming!