comp_mods.Rd
This function takes in one or more linear regression models and compares the RMSE, R2 and MAE of those models with or without a new input data.
comp_mods(mod1, ..., newdata = NULL)
mod1 | an object containing results returned by lm function |
---|---|
... | additional lm model object |
newdata | newdata than used for training the model. By default NULL and the function evaluated model performance based on training data |
a dataframe with each row representing an input model and three columns of model performance evaluation criteria (RMSE, R2 and MAE)
train <- mtcars[1:20,] test <- mtcars[21:30,] mod1 <- lm(mpg~wt, train) mod2 <- lm(mpg~cyl, train) mod3 <- lm(mpg~wt+cyl, train) mod4 <- lm(mpg~carb, train) comp_mods(mod1, mod2, mod3, mod4, newdata = test)#> RMSE Rsquared MAE #> model1 7.558188 0.0276731943 6.090093 #> model2 8.893606 0.0006549141 7.565000 #> model3 8.315105 0.0044296323 6.741422 #> model4 9.741102 0.1946252582 7.860596