Skip to contents

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,
  ...
)

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).

criterion

the model selection criterion. Must be one of "aic", "bic", and "loglik". Defaults to "aic".

na.rm

logical. Should missing values be removed?

...

unused.

Value

model_select returns an object of class

univariateML. This is a named numeric vector with maximum likelihood estimates for the parameters of the best fitting model and the following attributes:

model

The name of the model.

density

The density associated with the estimates.

logLik

The loglikelihood at the maximum.

support

The support of the density.

n

The number of observations.

call

The call as captured my match.call

See also

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

Examples

# Select among all possible models.
model_select(precip)
#> Maximum likelihood estimates for the Skew Normal model 
#>    mean       sd       xi  
#> 34.6957  13.5471   0.8088  

# View possible models to fit.
print(univariateML_models)
#>  [1] "beta"       "betapr"     "cauchy"     "exp"        "gamma"     
#>  [6] "ged"        "gumbel"     "invgamma"   "invgauss"   "invweibull"
#> [11] "kumar"      "laplace"    "lgamma"     "llogis"     "lnorm"     
#> [16] "logis"      "logitnorm"  "lomax"      "naka"       "norm"      
#> [21] "pareto"     "power"      "rayleigh"   "sged"       "snorm"     
#> [26] "sstd"       "std"        "unif"       "weibull"   

# Try out only gamma, Weibull, and exponential.
model_select(precip, c("gamma", "weibull", "exp"))
#> Maximum likelihood estimates for the Weibull model 
#>  shape   scale  
#>  2.829  39.084