get_r2: Estimate R2 or Pseudo-R2 from regression models

View source: R/display_functions.R

get_r2R Documentation

Estimate R2 or Pseudo-R2 from regression models

Description

get_r2 is a is a wrap function that calls r2 from package performance. Calculates the R2 or pseudo-R2 value for different regression model objects, returning a character object for easy printing in tables of coefficients.

Usage

get_r2(model, ...)

Arguments

model

A statistical regression model.

...

Additional arguments passed to r2.

Details

The main purpose of get_r2 is to allow easy printing of R2 value in tables of coefficients (see examples).

See Also

r2.

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)

model_norm %>%
  glm_coef(labels = model_labels(model_norm)) %>%
  as_hux() %>%
  set_align(everywhere, 2:3, "right") %>%
  theme_pubh() %>%
  add_footnote(get_r2(model_norm), font_size = 9)

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