model_list_terms_levels {broom.helpers}R Documentation

List levels of categorical terms

Description

Only for categorical variables with treatment, SAS, sum or successive differences contrasts (cf. MASS::contr.sdif()), and categorical variables with no contrast.

Usage

model_list_terms_levels(
  model,
  label_pattern = "{level}",
  variable_labels = NULL,
  sdif_term_level = c("diff", "ratio")
)

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

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()

sdif_term_level

for successive differences contrasts, how should term levels be named? "diff" for "B - A" (default), "ratio" for "B / A"

Value

A tibble with ten columns:

See Also

Other model_helpers: model_compute_terms_contributions(), model_get_assign(), model_get_coefficients_type(), model_get_contrasts(), model_get_model(), model_get_model_frame(), model_get_model_matrix(), model_get_n(), model_get_nlevels(), model_get_offset(), model_get_pairwise_contrasts(), model_get_response(), model_get_response_variable(), model_get_terms(), model_get_weights(), model_get_xlevels(), model_identify_variables(), model_list_contrasts(), model_list_higher_order_variables(), model_list_variables()

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))}"
)

[Package broom.helpers version 1.15.0 Index]