Learn R Programming

univariateML (version 1.5.0)

model_select: Fit multiple models and select the best fit

Description

Selects the best model by log-likelihood, aic, or bic.

Usage

model_select(
  x,
  models = univariateML_models,
  criterion = c("AIC", "BIC", "logLik"),
  na.rm = FALSE,
  type = c("both", "discrete", "continuous"),
  return = c("best", "all"),
  ...
)

Value

The return value depends on the return argument. For return = "best" (default), model_select returns an object of class

univariateML

For return = "all", model_select returns a tibble data frame with the following columns:

model

The name of the model.

d_loglik, d_aic, d_bic

See loglik, aic, bic.

p

Number of parameters fitted.

loglik, aic, bic

The negative log-likelihood at the maximum, the aic, and the bic, respectively. The minimum of each of these is noted and then subtracted from each value to give their delta versions d_loglik, d_aic, d_bic

. So, the model with the lowest aic will have d_aic of 0; the d_aic of all the other models shows how much higher their aics are from the minimum. The same goes with d_loglik and d_bic.

ml

The internal code name for the model.

univariateML

The univariateML object for the model. This is return = "all", this object is returned for all tested models.

Arguments

x

a (non-empty) numeric vector of data values.

models

a character vector containing the distribution models to select from; see print(univariateML_models). Defaults to all implemented models.

criterion

the model selection criterion. Must be one of "AIC", "BIC", and "logLik", ignoring case. Defaults to "AIC".

na.rm

logical. Should missing values be removed?

type

Either "both", "discrete", or "continuous". The supplied models vector is restricted to the desired class.

return

character length 1. "univariateML" (default) if the function should return the single best model; "all" if a tibble data frame of all results should be returned, sorted by decreasing model performance.

...

unused.

See Also

Johnson, N. L., Kotz, S. and Balakrishnan, N. (1995) Continuous Univariate Distributions, Volume 1, Chapter 17. Wiley, New York.

Examples

Run this code
# Select among all possible continuous models.
model_select(precip, type = "continuous")

# View possible models to fit.
print(univariateML_models)

# Try out only gamma, Weibull, and exponential.
model_select(precip, c("gamma", "weibull", "exp"))

# Fit the discrete `corbet` data to all available discrete models
model_select(corbet, type = "discrete", return = "all")

Run the code above in your browser using DataLab