Skip to contents

This function extracts residuals from a fast regression model table (fast_regression()).

Usage

extract_regression_residuals(.model_tbl)

Arguments

.model_tbl

A fast regression model specification table (fst_reg_spec_tbl).

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.

Author

Steven P. Sanderson II, MPH

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