e_lm_model_criteria: Return table of model selection criteria

View source: R/e_lm_model_criteria.R

e_lm_model_criteriaR Documentation

Return table of model selection criteria

Description

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 (NA if y ~ 1 intercept-only 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.

Usage

e_lm_model_criteria(lm_fit = NULL, dat_fit = NULL, model_id = NULL)

Arguments

lm_fit

fitted model object

dat_fit

data used for model fit

model_id

label for each model that is fit, helps to match up with original model

Value

     a tibble of model selection criteria

Examples

lm_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 |> print(width = Inf)

# intercept-only model
lm_form <- formula(mpg ~ 1)
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 |> print(width = Inf)

erikerhardt/erikmisc documentation built on April 17, 2025, 10:48 a.m.