Add significance stars to estimates with small p-values
Arguments
- x
(
gtsummary
)
A'gtsummary'
object with a'p.value'
column- pattern
(
string
)
glue-syntax string indicating what to display in formatted column. Default is"{estimate}{stars}"
for regression summaries and"{p.value}{stars}"
otherwise. A footnote is placed on the first column listed in the pattern. Other common patterns are"{estimate}{stars} ({conf.low}, {conf.high})"
and"{estimate} ({conf.low} to {conf.high}){stars}"
- thresholds
(
numeric
)
Thresholds for significance stars. Default isc(0.001, 0.01, 0.05)
- hide_ci
(scalar
logical
)
logical whether to hide confidence interval. Default isTRUE
- hide_p
(scalar
logical
)
logical whether to hide p-value. Default isTRUE
for regression summaries, andFALSE
otherwise.- hide_se
(scalar
logical
)
logical whether to hide standard error. Default isFALSE
Examples
tbl <-
lm(time ~ ph.ecog + sex, survival::lung) |>
tbl_regression(label = list(ph.ecog = "ECOG Score", sex = "Sex"))
# Example 1 ----------------------------------
tbl |>
add_significance_stars(hide_ci = FALSE, hide_p = FALSE)
Characteristic
Beta1
SE
95% CI
p-value
Abbreviations: CI = Confidence Interval, SE = Standard Error
1 *p<0.05; **p<0.01; ***p<0.001
# Example 2 ----------------------------------
tbl |>
add_significance_stars(
pattern = "{estimate} ({conf.low}, {conf.high}){stars}",
hide_ci = TRUE, hide_se = TRUE
) |>
modify_header(estimate = "**Beta (95% CI)**") |>
modify_abbreviation("CI = Confidence Interval")
Characteristic
Beta (95% CI)1
Abbreviation: CI = Confidence Interval
1 *p<0.05; **p<0.01; ***p<0.001
# Example 3 ----------------------------------
# Use ' \n' to put a line break between beta and SE
tbl |>
add_significance_stars(
hide_se = TRUE,
pattern = "{estimate}{stars} \n({std.error})"
) |>
modify_header(estimate = "**Beta \n(SE)**") |>
modify_abbreviation("SE = Standard Error") |>
as_gt() |>
gt::fmt_markdown(columns = everything()) |>
gt::tab_style(
style = "vertical-align:top",
locations = gt::cells_body(columns = label)
)
Characteristic
Beta
(SE)1
Abbreviations: CI = Confidence Interval, SE = Standard Error
1 *p<0.05; **p<0.01; ***p<0.001
# Example 4 ----------------------------------
lm(marker ~ stage + grade, data = trial) |>
tbl_regression() |>
add_global_p() |>
add_significance_stars(
hide_p = FALSE,
pattern = "{p.value}{stars}"
)
Characteristic
Beta
SE
p-value1
Abbreviations: CI = Confidence Interval, SE = Standard Error
1 *p<0.05; **p<0.01; ***p<0.001