get_r2: Estimate R2 or Pseudo-R2 from regression models

Description Usage Arguments Details See Also Examples

View source: R/display_functions.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require(dplyr, quietly = TRUE)
require(sjlabelled, quietly = TRUE)
require(huxtable, 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(1) %>%
  add_footnote(get_r2(model_norm), font_size = 9)

pubh documentation built on Feb. 17, 2021, 1:08 a.m.