Skip to contents

Get the name of the response variable

Usage

model_get_response_variable(model)

# Default S3 method
model_get_response_variable(model)

Arguments

model

(a model object, e.g. glm)
A model object.

Examples

lm(hp ~ mpg + factor(cyl) + disp:hp, mtcars) |>
  model_get_response_variable()
#> [1] "hp"

mod <- glm(
  response ~ stage * grade + trt,
  gtsummary::trial,
  family = binomial
)
mod |> model_get_response_variable()
#> [1] "response"

mod <- glm(
  Survived ~ Class * Age + Sex,
  data = Titanic |> as.data.frame(),
  weights = Freq,
  family = binomial
)
mod |> model_get_response_variable()
#> [1] "Survived"