moderndive (version 0.2.0)

get_regression_points: Get regression points

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

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

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab