# aicbic

Akaike or Bayesian information criteria

## Syntax

``aic = aicbic(logL,numParam)``
``````[aic,bic] = aicbic(logL,numParam,numObs)``````

## Description

example

````aic = aicbic(logL,numParam)` returns Akaike information criteria (AIC) corresponding to optimized loglikelihood function values (`logL`), as returned by `estimate`, and the model parameters, `numParam`.```

example

``````[aic,bic] = aicbic(logL,numParam,numObs)``` additionally returns Bayesian information criteria (BIC) corresponding to `logL`, `numParam`, and the sample sizes associated with each `logL` value.```

## Examples

collapse all

Calculate and interpret the AIC for four models.

The loglikelihood function values (`logL`) and the number of model parameters (`numParam`) from four multivariate time series analyses are:

```logL1 = -681.4724; logL2 = -632.3158; logL3 = -663.4615; logL4 = -605.9439; numParam1 = 12; numParam2 = 27; numParam3 = 18; numParam4 = 45;```

Calculate the AIC.

```aic = aicbic([logL1,logL2,logL3,logL4], ... [numParam1,numParam2,numParam3,numParam4])```
```aic = 1×4 103 × 1.3869 1.3186 1.3629 1.3019 ```

The model with the lowest AIC has the best fit. Therefore, the fourth model fits best.

Compare information criteria statistics for several model fits.

Specify the model

`${y}_{t}=-4+0.2{y}_{t-1}+0.5{y}_{t-2}+{\epsilon }_{t},$`

where ${\epsilon }_{t}$ is Gaussian with mean 0 and variance 2. Simulate data from this model.

```rng(1); % For random data reproducibility T = 100; % Sample size DGP = arima('Constant',-4,'AR',[0.2, 0.5], ... 'Variance',2); y = simulate(DGP,T);```

Define three competing models to fit to the data.

```EstMdl1 = arima('ARLags',1); EstMdl2 = arima('ARLags',1:2); EstMdl3 = arima('ARLags',1:3);```

Fit the models to the data.

```logL = zeros(3,1); % Preallocate loglikelihood vector [~,~,logL(1)] = estimate(EstMdl1,y,'Display','off'); [~,~,logL(2)] = estimate(EstMdl2,y,'Display','off'); [~,~,logL(3)] = estimate(EstMdl3,y,'Display','off');```

Compute the AIC and BIC for each model.

`[aic,bic] = aicbic(logL, [3; 4; 5], T*ones(3,1))`
```aic = 3×1 381.7732 358.2422 358.8479 ```
```bic = 3×1 389.5887 368.6629 371.8737 ```

The model containing two autoregressive lag parameters fits best since it yields the lowest information criteria. The structure of the best fitting model matches the model structure that simulated the data.

## Input Arguments

collapse all

Optimized loglikelihood objective function values associated with various model fits, specified as a scalar or vector.

Obtain an optimized loglikelihood value using `estimate`, `infer`, `estimate`, or an Optimization Toolbox™ function such as `fmincon` or `fminunc`.

Data Types: `double` | `single`

Number of estimated parameters associated with each corresponding fitted model in `logL`, specified as a positive integer, or a vector of positive integers having the same length as `logL`.

If `numParam` is a scalar, then `aicbic` applies it to all `logL` values.

For univariate time series models, use `length(info.X)` to obtain `numParam` from a fitted model returned by `estimate`.

For VAR models, obtain `numParam` using `summarize` from an estimated `varm` model object.

Data Types: `double` | `single`

Sample sizes of the observed series associated with each corresponding fitted model in `logL`, specified as a positive integer, or a vector of positive integers having the same length as `logL`.

`aicbic` requires `numObs` to compute the BIC.

If `numObs` is a scalar, then `aicbic` applies it to all `logL` values.

Data Types: `double` | `single`

## Output Arguments

collapse all

AIC statistics associated with each corresponding fitted model in `logL`, returned as a vector with the same length as `logL`.

BIC statistics associated with each corresponding fitted model in `logL`, returned as a vector with the same length as `logL`.

collapse all

### Akaike Information Criterion

A model fit statistic considers goodness-of-fit and parsimony. Select models that minimize AIC.

When comparing multiple model fits, additional model parameters often yield larger, optimized loglikelihood values. Unlike the optimized loglikelihood value, AIC penalizes for more complex models, i.e., models with additional parameters.

The formula for AIC, which provides insight into its relationship to the optimized loglikelihood and its penalty for complexity, is:

`$aic=-2\left(logL\right)+2\left(numParam\right).$`

### Bayesian Information Criterion

A model fit statistic considers goodness-of-fit and parsimony. Select models that minimize BIC.

Like AIC, BIC uses the optimal loglikelihood function value and penalizes for more complex models, i.e., models with additional parameters. The penalty of BIC is a function of the sample size, and so is typically more severe than that of AIC.

The formula for BIC is:

`$bic=-2\left(logL\right)+numParam*\mathrm{log}\left(numObs\right).$`

 Box, G. E. P., G. M. Jenkins, and G. C. Reinsel. Time Series Analysis: Forecasting and Control. 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1994.