Skip to contents

Adds the statistics of the model as a whole, such as R², the log-likelihood and AIC, either as rows at the bottom of the table (add_glance_table()) or as a source note (add_glance_source_note()). The statistics come from glance_fun, by default glance_fun_s3(), which computes them in base R for lm, glm and coxph models and calls broom::glance() for other classes.

Usage

add_glance_table(
  x,
  include = everything(),
  label = NULL,
  fmt_fun = list(everything() ~ label_style_sigfig(digits = 3), any_of("p.value") ~
    label_style_pvalue(digits = 1), c(where(is.integer), starts_with("df")) ~
    label_style_number()),
  glance_fun = glance_fun_s3(x$inputs$x)
)

add_glance_source_note(
  x,
  include = everything(),
  label = NULL,
  fmt_fun = list(everything() ~ label_style_sigfig(digits = 3), any_of("p.value") ~
    label_style_pvalue(digits = 1), c(where(is.integer), starts_with("df")) ~
    label_style_number()),
  glance_fun = glance_fun_s3(x$inputs$x),
  text_interpret = c("md", "html"),
  sep1 = " = ",
  sep2 = "; "
)

Arguments

x

(tbl_regression)
A table created with tbl_regression().

include

(selector)
Statistics to include, selected among the columns glance_fun returns. Default is everything().

label

(formula-list)
Labels for the statistics, e.g. list(r.squared ~ "R2"). The defaults are gtsummary's: r.squared "R²", adj.r.squared "Adjusted R²", sigma "Sigma", statistic "Statistic", p.value "p-value", logLik "Log-likelihood", deviance "Deviance", df.residual "Residual df", null.deviance "Null deviance", df.null "Null df", nevent "N events", concordance "c-index", std.error.concordance "c-index SE", nobs "No. Obs."; any other statistic is labelled with its name.

fmt_fun

(formula-list)
Formatting functions for the statistics. Default formats p-values with label_style_pvalue(digits = 1), integers and the df* statistics with label_style_number() and everything else with label_style_sigfig(digits = 3).

glance_fun

(function)
Function that returns a one-row data frame of model statistics. Default is glance_fun_s3(x$inputs$x).

text_interpret

(string)
How the source note is interpreted, "md" (the default) or "html".

sep1

(string)
Separator between a label and its value in the source note. Default is " = ".

sep2

(string)
Separator between statistics in the source note. Default is "; ".

Value

The table with the statistics as rows (row_type = "glance_statistic") or as a source note.

Examples

# Example 1 ----------------------------------
lm(age ~ marker + grade, trial) |>
  tbl_regression() |>
  add_glance_table(include = c(r.squared, AIC, nobs))
# Example 2 ---------------------------------- glm(response ~ age + grade, trial, family = binomial) |> tbl_regression(exponentiate = TRUE) |> add_glance_source_note(include = c(nobs, AIC), label = list(nobs ~ "N"))