A dplyr compatible convenience function to add residuals to a data set

add_model_residuals(model = NULL, old_data = NULL)

Arguments

model

A model object from `fit_model`

old_data

The data set to which predicted values will be added.

Value

A data.frame object with residuals added.

Examples

data("yields", package="manymodelr")
yields1 <- yields[1:50,]
yields2 <- yields[51:100,]
lm_model <- fit_model(yields1,"weight","height","lm") 
head(add_model_residuals(lm_model, yields2))
#>    normal    height     weight    yield   residuals
#> 51    Yes 0.5876683 0.53966096 524.0298 -0.19588072
#> 52     No 0.1937264 0.46185381 516.9982  0.03232510
#> 53    Yes 0.3642414 0.07183639 527.1234  0.13322172
#> 54     No 0.6026853 0.21721278 536.8593  0.23862377
#> 55    Yes 0.5081495 0.16057305 516.6769  0.17555630
#> 56     No 0.5740309 0.53528679 518.9117 -0.08703343