View source: R/regression_functions.R
get_regression_points | R Documentation |
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.
get_regression_points(
model,
digits = 3,
print = FALSE,
newdata = NULL,
ID = NULL
)
model |
an |
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 |
ID |
A string indicating which variable in either the original data used to fit
|
A tibble-formatted regression table of outcome/response variable, all explanatory/predictor variables, the fitted/predicted value, and residual.
augment()
, get_regression_table()
, get_regression_summaries()
library(dplyr)
library(tibble)
# Convert rownames to column
mtcars <- mtcars %>%
rownames_to_column(var = "automobile")
# Fit lm() regression:
mpg_model <- lm(mpg ~ cyl, data = mtcars)
# Get information on all points in regression:
get_regression_points(mpg_model, ID = "automobile")
# Create training and test set based on mtcars:
training_set <- mtcars %>%
sample_frac(0.5)
test_set <- mtcars %>%
anti_join(training_set, by = "automobile")
# 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, ID = "automobile")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.