Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

model_list_terms_levels

List levels of categorical terms


Description

Only for categorical variables with treatment, SAS or sum contrasts, and categorical variables with no contrast.

Usage

model_list_terms_levels(
  model,
  label_pattern = "{level}",
  variable_labels = NULL
)

## Default S3 method:
model_list_terms_levels(
  model,
  label_pattern = "{level}",
  variable_labels = NULL
)

Arguments

model

a model object

label_pattern

a glue pattern for term labels (see examples)

variable_labels

an optional named list or named vector of custom variable labels passed to model_list_variables()

Value

A tibble with ten columns:

  • variable: variable

  • contrasts_type: type of contrasts ("sum" or "treatment")

  • term: term name

  • level: term level

  • level_rank: rank of the level

  • reference: logical indicating which term is the reference level

  • reference_level: level of the reference term

  • var_label: variable label obtained with model_list_variables()

  • var_nlevels: number of levels in this variable

  • dichotomous: logical indicating if the variable is dichotomous

  • label: term label (by default equal to term level) The first nine columns can be used in label_pattern.

See Also

Examples

glm(
  am ~ mpg + factor(cyl),
  data = mtcars,
  family = binomial,
  contrasts = list(`factor(cyl)` = contr.sum)
) %>%
  model_list_terms_levels()

df <- Titanic %>%
  dplyr::as_tibble() %>%
  dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))

mod <- df %>%
  glm(
    Survived ~ Class + Age + Sex,
    data = ., weights = .$n, family = binomial,
    contrasts = list(Age = contr.sum, Class = "contr.helmert")
  )
mod %>% model_list_terms_levels()
mod %>% model_list_terms_levels("{level} vs {reference_level}")
mod %>% model_list_terms_levels("{variable} [{level} - {reference_level}]")
mod %>% model_list_terms_levels(
  "{ifelse(reference, level, paste(level, '-', reference_level))}"
)

broom.helpers

Helpers for Model Coefficients Tibbles

v1.3.0
GPL-3
Authors
Joseph Larmarange [aut, cre] (<https://orcid.org/0000-0001-7097-700X>), Daniel D. Sjoberg [aut] (<https://orcid.org/0000-0003-0862-2018>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.