Skip to contents

Replaces the p-values of a regression table with one p-value per variable: a type III test of the hypothesis that all the coefficients of the variable are zero, which is what car::Anova(type = "III") computes and what gtsummary reports. The default anova_fun, global_pvalue_fun(), computes the tests in base R:

  • lm: Wald F test on the variable's coefficients, equal to the F test from refitting without the variable's columns;

  • glm: likelihood-ratio test from refitting without the variable (drop1() with the deviance scaled by the dispersion);

  • coxph: likelihood-ratio test from refitting without the variable (survival::coxph() on the model matrix).

Usage

add_global_p(
  x,
  include = everything(),
  keep = FALSE,
  anova_fun = global_pvalue_fun,
  type = "III",
  ...
)

Arguments

x

(tbl_regression, tbl_uvregression)
A regression table. For tbl_uvregression, the table must have been built with y.

include

(selector)
Variables to compute a global p-value for. Default is everything().

keep

(scalar logical)
Whether to keep the p-values of the individual levels. Default is FALSE, which blanks them.

anova_fun

(function)
Function that takes a model and type and returns a data frame with a term column naming the variables and a p.value column. Default is global_pvalue_fun().

type

(string)
Passed to anova_fun. Default is "III"; the built-in function accepts "III" and "II" ("II" drops each term from the model formula with stats::drop1(), which respects marginality).

...

Passed to anova_fun.

Value

The table with the global p-values in the p.value column.

Examples

# Example 1 ----------------------------------
glm(response ~ age + grade + trt, trial, family = binomial) |>
  tbl_regression(exponentiate = TRUE) |>
  add_global_p()
# Example 2 ---------------------------------- # keep the level p-values as well lm(marker ~ age + grade, trial) |> tbl_regression() |> add_global_p(keep = TRUE)