calculate_aic: Generic for calculating the AIC

View source: R/calculate_aic.R

calculate_aicR Documentation

Generic for calculating the AIC

Description

Generic calculate_aic() returns the Akaike's 'An Information Criterion' for the given input.

Usage

calculate_aic(x, ...)

## Default S3 method:
calculate_aic(x, ...)

## S3 method for class 'trending_model'
calculate_aic(x, data, as_tibble = FALSE, ...)

## S3 method for class 'list'
calculate_aic(x, data, ...)

## S3 method for class 'trending_fit'
calculate_aic(x, as_tibble = FALSE, ...)

## S3 method for class 'trending_fit_tbl'
calculate_aic(x, ...)

Arguments

x

An R object.

...

Not currently used.

data

a data.frame containing data (including the response variable and all predictors) used in the specified model.

as_tibble

Should the result be returned as tibble (as_tibble = TRUE) or a list (as_tibble = FALSE).

Details

Specific methods are given for trending_fit and trending_fit_tbl objects. The default method applies stats::AIC() directly.

Value

For a single trending_fit input, if as_tibble = FALSE the object returned will be a list with entries:

  • metric: "AIC"

  • result: the resulting AIC value fit (NULL if the calculation failed)

  • warnings: any warnings generated during calculation

  • errors: any errors generated during calculation

If as_tibble = TRUE, or the input is a trending_fit_tbl, then the output will be a tibble with one row for each fitted model columns corresponding to output generated with single model input.

Author(s)

Tim Taylor

#' @examples x = rnorm(100, mean = 0) y = rpois(n = 100, lambda = exp(1.5 + 0.5*x)) dat <- data.frame(x = x, y = y) poisson_model <- glm_model(y ~ x , family = "poisson") negbin_model <- glm_nb_model(y ~ x) fitted_model <- fit(poisson_model, dat) fitted_models <- fit(list(poisson_model, negbin_model), data = dat)

calculate_aic(poisson_model, dat) calculate_aic(fitted_model) calculate_aic(fitted_model, as_tibble = TRUE) calculate_aic(fitted_models)


reconhub/trendeval documentation built on Jan. 12, 2023, 12:36 a.m.