calculate_residuals | R Documentation |
From a model, calculate the predicted values from a set of data and then calculate the residuals of those predictions.
calculate_residuals(object, data = NULL)
## S3 method for class 'lm'
calculate_residuals(object, data = NULL)
object |
A model object (such as a fitted |
data |
(Optional) a data set used to create predictions (if omitted, the fitted values are used). |
This function will not work if transformations to variables are done in the
model formula (e.g., lm(mpg ~ wt + as.factor(vs), data = mtcars)
).
Variable transformations should be done to the data set before creating the
model formula.
A tibble with columns .pred
and .resid
.
library(tidytest)
#> `lm` Method
mod_lm_fit <- lm(mpg ~ disp + wt + hp, data = mtcars)
calculate_residuals(mod_lm_fit)
calculate_residuals(mod_lm_fit, mtcars[1:15, ])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.