Skip to contents

Adds a column with the number of observations in each model, on the label rows, and the number of observations in each level, on the level rows. The observation counts come from the model matrix: a level's N is the number of observations at that level.

Value

The table with a stat_n column.

Arguments

  • x (tbl_regression, tbl_uvregression)
    A regression table.

  • location (character)
    "label", "level" or both. "label" puts the model's N on the label rows, "level" puts each level's N on the level rows. Default is "label".

  • ... Not used.

Examples

# Example 1 ----------------------------------
glm(response ~ age + grade, trial, family = binomial) |>
  tbl_regression(exponentiate = TRUE) |>
  add_n(location = "level")
# Example 2 ---------------------------------- trial |> tbl_uvregression(y = age, include = c(marker, grade), method = lm, hide_n = TRUE) |> add_n(location = c("label", "level"))