
Extract Residuals from Fast Regression Models
Source:R/extract-regression-residuals.R
extract_regression_residuals.Rd
This function extracts residuals from a fast regression model
table (fast_regression()
).
Value
The function returns a list of data frames, each containing residuals, actual values, and predicted values for a specific model.
Details
The function checks if the input model specification table inherits the class 'fst_reg_spec_tbl' and if it contains the column 'pred_wflw'. It then manipulates the data, grouping it by model, and extracts residuals for each model. The result is a list of data frames, each containing residuals, actual values, and predicted values for a specific model.
See also
Other Extractor:
extract_model_spec()
,
extract_wflw_fit()
,
extract_wflw_pred()
,
extract_wflw()
,
get_model()
Examples
library(recipes, quietly = TRUE)
rec_obj <- recipe(mpg ~ ., data = mtcars)
fr_tbl <- fast_regression(mtcars, rec_obj, .parsnip_eng = c("lm","glm"),
.parsnip_fns = "linear_reg")
result <- extract_regression_residuals(fr_tbl)
head(result[[1]])
#> # A tibble: 6 × 4
#> .model_type .actual .predicted .resid
#> <chr> <dbl> <dbl> <dbl>
#> 1 lm - linear_reg 21 12.0 9.04
#> 2 lm - linear_reg 21 27.3 -6.31
#> 3 lm - linear_reg 22.8 19.2 3.62
#> 4 lm - linear_reg 21.4 24.8 -3.36
#> 5 lm - linear_reg 18.7 31.2 -12.5
#> 6 lm - linear_reg 18.1 14.1 3.96