Skip to contents

Adds stars next to the estimates, or the p-values, whose p-value falls below the thresholds, one star per threshold passed, with a footnote giving the thresholds, and hides the columns the stars stand in for. On a regression table the default pattern is "{estimate}{stars}" and the p-value column is hidden; on other tables it is "{p.value}{stars}" and the p-values stay.

Usage

add_significance_stars(
  x,
  pattern = ifelse(inherits(x, c("tbl_regression", "tbl_uvregression")),
    "{estimate}{stars}", "{p.value}{stars}"),
  thresholds = c(0.001, 0.01, 0.05),
  hide_ci = TRUE,
  hide_p = inherits(x, c("tbl_regression", "tbl_uvregression")),
  hide_se = FALSE
)

Arguments

x

(ltsummary)
A table with a p.value column.

pattern

(string)
A glue pattern over the table's columns and {stars}, shown in the first column it names, which also gets the footnote. Default is "{estimate}{stars}" for regression tables and "{p.value}{stars}" otherwise. Other common patterns are "{estimate}{stars} ({conf.low}, {conf.high})" and "{estimate} ({conf.low} to {conf.high}){stars}".

thresholds

(numeric)
The p-value thresholds, between 0 and 1. Default is c(0.001, 0.01, 0.05).

hide_ci

(scalar logical)
Whether to hide the confidence interval. Default is TRUE.

hide_p

(scalar logical)
Whether to hide the p-value. Default is TRUE for regression tables and FALSE otherwise.

hide_se

(scalar logical)
Whether to hide the standard error. Default is FALSE, which shows it on a regression table.

Value

The table with a hidden stars column and pattern merged into the first column it names.

See also

Examples

tbl <- lm(marker ~ age + grade, trial) |>
  tbl_regression(label = list(age = "Age", grade = "Grade"))

# Example 1 ----------------------------------
tbl |>
  add_significance_stars(hide_ci = FALSE, hide_p = FALSE)
# 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")
# Example 3 ---------------------------------- # stars on the p-values of a summary table trial |> tbl_summary(by = trt, include = c(age, grade), missing = "no") |> add_p() |> add_significance_stars()