Calculates a large set of model selection criteria and returns them in a one-row tibble.
AIC and BIC criteria from the stats package:
aic Akaike's An Information Criterion
bic Bayesian Information Criterion (AIC with k = log(nobs(object)))
caic Conditional Akaike Information for 'lme4' and 'lme'
nobs number of observations used to fit lm_fit
Several criteria from the lm summary:
r2 R-squared statistic
r2adj Adjusted R-squared statistic
f_stat F-statistic compared to grand mean model
p F-statistic numerator degrees-of-freedom (number of parameters in the model)
df F-statistic denominator degrees-of-freedom (number of df estimating the variance)
f_stat_pval F-statistic p-value
rse Residual standard error.
Several criteria are defined in ?modelr::`model-quality`:
Three summaries are immediately interpretible on the scale of the response variable:
rmse is the root-mean-squared-error
mae is the mean absolute error
qae is quantiles of absolute error.
Other summaries have varying scales and interpretations:
mape mean absolute percentage error.
rsae is the relative sum of absolute errors.
mse is the mean-squared-error.
rsquare is the variance of the predictions divided by the
variance of the response.
e_lm_model_criteria(lm_fit = NULL, dat_fit = NULL, model_id = NULL)fitted model object
data used for model fit
label for each model that is fit, helps to match up with original model
a tibble of model selection criterialm_form <- formula(mpg ~ cyl + carb + disp + hp + disp:hp + wt + vs + am + gear)
lm_fit <-
stats::lm(
formula = lm_form
, data = dat_mtcars_e
)
lm_crit <-
e_lm_model_criteria(
lm_fit = lm_fit
, dat_fit = dat_mtcars_e
, model_id = 1
)
lm_crit
#> # A tibble: 1 × 17
#> model_id aic bic nobs r2 r2adj f_stat p df f_stat…¹ rse mse
#> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 157. 175. 32 0.893 0.842 17.5 10 21 5.14e-8 2.40 3.78
#> # … with 5 more variables: rmse <dbl>, rsquare <dbl>, mae <dbl>, mape <dbl>,
#> # rsae <dbl>, and abbreviated variable name ¹f_stat_pval