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(moderndive)
# Fit lm() regression:
life_exp_model <- lm(
life_expectancy_2022 ~ gdp_per_capita,
data = un_member_states_2024
)
# Get information on all points in regression:
get_regression_points(life_exp_model, ID = "country")
# Create training and test set based on un_member_states_2024:
training_set <- un_member_states_2024 %>%
sample_frac(0.5)
test_set <- un_member_states_2024 %>%
anti_join(training_set, by = "country")
# Fit model to training set:
life_exp_model_train <- lm(
life_expectancy_2022 ~ gdp_per_capita,
data = training_set
)
# Make predictions on test set:
get_regression_points(life_exp_model_train, newdata = test_set, ID = "country")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.