model_labels: Using labels as coefficient names in tables of coefficients.

View source: R/display_functions.R

model_labelsR Documentation

Using labels as coefficient names in tables of coefficients.

Description

model_labels replaces row names in glm_coef with labels from the original data frame.

Usage

model_labels(model, intercept = TRUE)

Arguments

model

A generalised linear model.

intercept

Logical, should the intercept be added to the list of coefficients?

Details

model_labels does not handle yet interaction terms, see examples.

Please read the Vignette on Regression for more examples.

Examples

require(dplyr, quietly = TRUE)
require(sjlabelled, quietly = TRUE)

data(birthwt, package = "MASS")
birthwt <- birthwt %>%
  mutate(
    smoke = factor(smoke, labels = c("Non-smoker", "Smoker")),
    race = factor(race, labels = c("White", "African American", "Other"))
  ) %>%
  var_labels(
    bwt = "Birth weight (g)",
    smoke = "Smoking status",
    race = "Race"
  )

model_norm <- lm(bwt ~ smoke + race, data = birthwt)

glm_coef(model_norm, labels = model_labels(model_norm))

model_int <- lm(formula = bwt ~ smoke * race, data = birthwt)

model_int %>%
  glm_coef(labels = c(
    model_labels(model_int),
    "Smoker: African American",
    "Smoker: Other"
  ))

josie-athens/pubh documentation built on Feb. 3, 2024, 4:32 a.m.