## Estimate AR and ARMA Models

AR and ARMA models are autoregressive parametric models that have no measured inputs. These models operate on time series data.

• The AR model contains a single polynomial A that operates on the measured output. For a single-output signal y(t), the AR model is given by the following equation:

`$A\left(q\right)y\left(t\right)=e\left(t\right)$`
• The ARMA model adds a second polynomial C that calculates the moving average of the noise error. The ARMA model for a single-output time series is given by the following equation:

`$A\left(q\right)y\left(t\right)=C\left(q\right)e\left(t\right)$`

The ARMA structure reduces to the AR structure for C(q) = 1.

The AR and ARMA model structures are special cases of the more general ARX and ARMAX model structures, which do provide for measured inputs. You can estimate AR and ARMA models at the command line and in the app.

### Estimate AR and ARMA Models at the Command Line

Estimate AR and ARMA models at the command line by using `ar`, `arx`, `ivar`, or `armax` with estimation data that contains only output measurements. These functions return estimated models that are represented by `idpoly` model objects.

Selected Commands for Estimating Polynomial AR and ARMA Time-Series Models

FunctionDescription
`ar`

Noniterative, least-squares method to estimate linear, discrete-time, single-output AR models. Provides algorithmic options including lattice-based approaches and the Yule-Walker covariance approach.

Example: ```sys = ar(y,na)``` estimates an AR model `sys` of polynomial order `na` from the scalar time series `y`.

`arx`

Noniterative, least-squares method for estimating linear AR models. Supports multiple outputs. Assumes white noise.

Example: `sys = arx(y,na)` estimates an AR model from the multiple-output time series `y`.

`ivar`

Noniterative, instrumental variable method for estimating single-output AR models. Insensitive to noise color.

Example: `sys = ivar(y,na)` estimates an AR model using the instrumental variable method for the scalar time series `y`.

`armax`

Iterative prediction-error method to estimate linear ARMA models.

Example: ```sys = armax(y,[na nc])``` of estimates an ARMA model of polynomial orders `na` and `nc` from the time series `y`.

For more detailed usage information and examples, as well as information on other models that these functions can estimate, see `ar`, `arx`, `ivar`, and `armax`.

### Estimate AR and ARMA Time Series Models in the App

Before you begin, complete the following steps:

Estimate AR and ARMA models using the System Identification app by following these steps.

1. In the System Identification app, select Estimate > Polynomial Models to open the Polynomial Models dialog box.

2. In the Structure list, select the polynomial model structure you want to estimate from the following options:

• `AR:[na]`

• `ARMA:[na nc]`

This action updates the options in the Polynomial Models dialog box to correspond with this model structure.

3. In the Orders field, specify the model orders.

• For single-output models, enter the model orders according to the sequence displayed in the Structure field.

• For multiple-output ARX models, enter the model orders directly, as described in Polynomial Sizes and Orders of Multi-Output Polynomial Models. Alternatively, enter the name of the matrix `NA` in the MATLAB Workspace browser that stores model orders, which is `Ny`-by-`Ny`.

To enter model orders and delays using the Order Editor dialog box, click .

4. (AR models only) Select the estimation Method as ARX or IV (instrumental variable method). For more information about these methods, see Polynomial Model Estimation Algorithms.

5. Select Add noise integration if you want to include an integrator in noise source e(t). This selection changes an AR model into an ARI model ($Ay=\frac{e}{1-{q}^{-1}}$) and an ARMA model into an ARIMA model ($Ay=\frac{C}{1-{q}^{-1}}e\left(t\right)$).

6. In the Name field, edit the name of the model or keep the default. The name of the model must be unique in the Model Board.

7. In the Initial state list, specify how you want the algorithm to treat initial states. For more information about the available options, see Specifying Initial States for Iterative Estimation Algorithms.

If you get an inaccurate fit, try setting a specific method for handling initial states rather than specifying automatic selection.

8. In the Covariance list, select `Estimate` if you want the algorithm to compute parameter uncertainties. Effects of such uncertainties are displayed on plots as model confidence regions.

If you do not want the algorithm to estimate uncertainty, select `None`. Skipping uncertainty computation can reduce computation time for complex models and large data sets.

9. Click to obtain regularized estimates of model parameters. Specify regularization constants in the Regularization Options dialog box. For more information, see Regularized Estimates of Model Parameters.

10. To view the estimation progress at the command line, select the Display progress check box. During estimation, the following information is displayed for each iteration:

• Loss function — Determinant of the estimated covariance matrix of the input noise.

• Parameter values — Values of the model structure coefficients you specified.

• Search direction — Changes in parameter values from the previous iteration.

• Fit improvements — Actual versus expected improvements in the fit.

11. Click to add this model to the Model Board in the System Identification app.

12. For the prediction-error method, only, to stop the search and save the results after the current iteration completes, click . To continue iterations from the current model, click the Continue iter button to assign current parameter values as initial guesses for the next search and start a new search. For the multi-output case, you can stop iterations for each output separately. Note that the software runs independent searches for each output.

13. To plot the model, select the appropriate check box in the Model Views area of the System Identification app.

You can export the model to the MATLAB workspace for further analysis by dragging it to the To Workspace rectangle in the System Identification app.