Skip to contents

Add the type of coefficients ("generic", "logistic", "poisson", "relative_risk" or "prop_hazard") and the corresponding coefficient labels, as attributes to x (respectively named coefficients_type and coefficients_label).

Usage

tidy_add_coefficients_type(
  x,
  exponentiate = attr(x, "exponentiate"),
  model = tidy_get_model(x)
)

Arguments

x

(data.frame)
A tidy tibble as produced by tidy_*() functions.

exponentiate

(logical)
Whether or not to exponentiate the coefficient estimates. It should be consistent with the original call to broom::tidy().

model

(a model object, e.g. glm)
The corresponding model, if not attached to x.

Examples

ex1 <- lm(hp ~ mpg + factor(cyl), mtcars) |>
  tidy_and_attach() |>
  tidy_add_coefficients_type()
attr(ex1, "coefficients_type")
#> [1] "generic"
attr(ex1, "coefficients_label")
#> [1] "Beta"

df <- Titanic |>
  dplyr::as_tibble() |>
  dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
ex2 <- glm(
  Survived ~ Class + Age * Sex,
  data = df,
  weights = df$n,
  family = binomial
) |>
  tidy_and_attach(exponentiate = TRUE) |>
  tidy_add_coefficients_type()
attr(ex2, "coefficients_type")
#> [1] "logistic"
attr(ex2, "coefficients_label")
#> [1] "OR"