get_regression_points: Get regression points

Description Usage Arguments Value See Also Examples

View source: R/regression_functions.R

Description

Output information on each point/observation used in an lm() regression in "tidy" format. This function is a wrapper function for broom::augment() and renames the variables to have more intuitive names.

Usage

1
get_regression_points(model, digits = 3, print = FALSE, newdata = NULL)

Arguments

model

an lm() model object

digits

number of digits precision in output table

print

If TRUE, return in print format suitable for R Markdown

newdata

A new data frame of points/observations to apply model to obtain new fitted values and/or predicted values y-hat. Note the format of newdata must match the format of the original data used to fit model.

Value

A tibble-formatted regression table of outcome/response variable, all explanatory/predictor variables, the fitted/predicted value, and residual.

See Also

augment, get_regression_table, get_regression_summaries

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(moderndive)
library(dplyr)
library(tibble)

# Fit lm() regression:
mpg_model <- lm(mpg ~ cyl, data = mtcars)

# Get information on all points in regression:
get_regression_points(mpg_model)

# Create training and test set based on mtcars: 
mtcars <- mtcars %>% 
  rownames_to_column(var = "model")
training_set <- mtcars %>% 
  sample_frac(0.5)
test_set <- mtcars %>% 
  anti_join(training_set, by = "model")

# Fit model to training set:
mpg_model_train <- lm(mpg ~ cyl, data = training_set)

# Make predictions on test set:
get_regression_points(mpg_model_train, newdata = test_set)

moderndive/moderndive documentation built on July 11, 2018, 3:02 a.m.