Autoregressive moving average model

# Overview
In statistics, autoregressive moving average (ARMA) models, sometimes called Box-Jenkins models after the iterative Box-Jenkins methodology usually used to estimate them, are typically applied to time series data.
Given a time series of data Xt, the ARMA model is a tool for understanding and, perhaps, predicting future values in this series.  The model consists of two parts, an autoregressive (AR) part and a moving average (MA) part.  The model is usually then referred to as the ARMA(p,q) model where p is the order of the autoregressive part and q is the order of the moving average part (as defined below).

# Autoregressive model
The notation AR(p) refers to the autoregressive model of order p. The AR(p) model is written
where \varphi_1, \ldots, \varphi_p are the parameters of the model, c is a constant and \varepsilon_t is an error term (see below).  The constant term is omitted by many authors for simplicity.
An autoregressive model is essentially an infinite impulse response filter with some additional interpretation placed on it.
Some constraints are necessary on the values of the parameters of this model in order that the model remains stationary.  For example, processes in the AR(1) model with |1| > 1 are not stationary.

## Example: An AR(1)-process
An AR(1)-process is given by:
where \varepsilon_t is a white noise process with zero mean and variance \sigma^2.
(Note: The subscript on \varphi_1 has been dropped.) The process is covariance-stationary if |\varphi|.  If \varphi=1 then X_t exhibits a unit root and can also be considered as a random walk, which is not covariance-stationary. Otherwise, the calculation of the expectation of X_t is straightforward. Assuming covariance-stationarity we get
thus:
where \mu is the mean.
For c = 0, then the mean = 0 and the variance is found to be:
The autocovariance is given by
It can be seen that the autocovariance function decays with a decay time of \tau=-1/\ln(\varphi) 
The spectral density function is the Fourier transform of the autocovariance function. In discrete terms this will be the discrete-time Fourier transform:
\frac{1}{\sqrt{2\pi}}\,\sum_{n=-\infty}^\infty B_n e^{-i\omega n}
=\frac{1}{\sqrt{2\pi}}\,\left(\frac{\sigma^2}{1+\varphi^2-2\varphi\cos(\omega)}\right).
This expression contains aliasing due to the discrete nature of the X_j, which is manifested as the cosine term in the denominator.  If we assume that the sampling time (\Delta t=1) is much smaller than the decay time (\tau), then we can use a continuum approximation to B_n:
which yields a Lorentzian profile for the spectral density:
=\frac{1}{\sqrt{2\pi}}\,\frac{\sigma^2}{1-\varphi^2}\,\frac{\gamma}{\pi(\gamma^2+\omega^2)}
where \gamma=1/\tau is the angular frequency associated with the decay time \tau.
An alternative expression for X_t can be derived by first substituting c+\varphi X_{t-2}+\varepsilon_{t-1} for X_{t-1} in the defining equation. Continuing this process N times yields
For N approaching infinity, \varphi^N will approach zero and:
It is seen that X_t is white noise convolved with the \varphi^k kernel plus the constant mean. By the central limit theorem, the X_t will be normally distributed as will any sample of X_t which is much longer than the decay time of the autocorrelation function.

## Calculation of the AR parameters
The AR(p) model is given by the equation
It is based on parameters \varphi_i where i = 1, ..., p. Those parameters may be calculated using least squares regression or the Yule-Walker equations:
\gamma_m = \sum_{k=1}^p \varphi_k \gamma_{m-k} + \sigma_\varepsilon^2\delta_m
where m = 0, ... , p, yielding p + 1 equations. \gamma_m is the autocorrelation function of X, \sigma_\varepsilon is the standard deviation of the input noise process, and m is the Kronecker delta function.
Because the last part of the equation is non-zero only if m = 0, the equation is usually solved by representing it as a matrix for m > 0, thus getting equation
\gamma_1 \\
\gamma_2 \\
\gamma_3 \\
\vdots \\
\end{bmatrix}
\begin{bmatrix}
\gamma_0 & \gamma_{-1} & \gamma_{-2} & \dots \\
\gamma_1 & \gamma_0 & \gamma_{-1} & \dots \\
\gamma_2 & \gamma_{1} & \gamma_{0} & \dots \\
\dots      & \dots         & \dots       & \dots \\
\end{bmatrix}
\begin{bmatrix}
\varphi_{1} \\
\varphi_{2} \\
\varphi_{3} \\
\end{bmatrix}
solving all \varphi. For m = 0 have
\gamma_0 = \sum_{k=1}^p \varphi_k \gamma_{-k} + \sigma_\varepsilon^2
which allows us to solve \sigma_\varepsilon^2.

### Derivation
The equation defining the AR process is
Multiplying both sides by Xt  m and taking expected value yields
Now, E = m by definition of the autocorrelation function. The values of the noise function are independent of each other, and Xt  m is independent of t where m is greater than zero. For m > 0, E = 0. For m = 0,
= E\left
= \sum_{i=1}^p \varphi_i\, E + E
= 0 + \sigma_\varepsilon^2,
Now we have, for m  0,
Furthermore,
= \sum_{i=1}^p \varphi_i\,E
= \sum_{i=1}^p \varphi_i\,\gamma_{m-i},
which yields the Yule-Walker equations:
for m  0.   For m < 0,

# Moving average model
The notation MA(q) refers to the moving average model of order q:
where the 1, ..., q are the parameters of the model and the t, t-1,... are again, the error terms. The moving average model is essentially a finite impulse response filter with some additional interpretation placed on it.

# Autoregressive moving average model
The notation ARMA(p, q) refers to the model with p autoregressive terms and q moving average terms. This model contains the AR(p) and MA(q) models,

# Note about the error terms
The error terms t are generally assumed to be independent identically-distributed random variables (i.i.d.)  sampled from a normal distribution with zero mean: t ~ N(0,2) where 2 is
the variance.  These assumptions may be weakened but doing so will change the properties of the model.  In particular, a change to the i.i.d. assumption would make a rather fundamental difference.

# Specification in terms of lag operator
In some texts the models will be specified in terms of the lag operator L.  In these terms then the AR(p) model is given by
where  represents the polynomial
The MA(q) model is given by
where  represents the polynomial
Finally, the combined ARMA(p, q) model is given by
-r more concisely,

# Fitting models
ARMA models in general can, after choosing p and q, be fitted by least squares regression to find the values of the parameters which minimize the error term.  It is generally considered good practice to find the smallest values of p and q which provide an acceptable fit to the data.  For a pure AR model the Yule-Walker equations may be used to provide a fit.

# Applications
ARMA is appropriate when a system is a function of a series of unobserved shocks (the MA part) as well as its own behavior.  For example, stock prices may be shocked by fundamental information as well as exhibiting technical trending and mean-reversion effects due to market participants.

# Generalizations
The dependence of Xt on past values and the error terms t is assumed to be linear unless specified otherwise. If the dependence is nonlinear, the model is specifically called a nonlinear moving average (NMA), nonlinear autoregressive (NAR), or nonlinear autoregressive moving average (NARMA) model.
Autoregressive moving average models can be generalized in other ways. See also autoregressive conditional heteroskedasticity (ARCH) models and autoregressive integrated moving average (ARIMA) models.  If multiple time series are to be fitted then a vector ARIMA (or VARIMA) model may be fitted.  If the time-series in question exhibits long memory then fractional ARIMA (FARIMA, sometimes called ARFIMA) modelling is appropriate.  If the data is thought to contain seasonal effects, it may be modeled by a SARIMA (seasonal ARIMA) or a periodic ARMA model.
Another generalization is the multiscale autoregressive (MAR) model.  A MAR model is indexed by the nodes of a tree, whereas a standard (discrete time) autoregressive model is indexed by integers.  See multiscale autoregressive model for a list of references.

## Autoregressive moving average model with exogenous inputs model (ARMAX model)
The notation ARMAX(p, q, b) refers to the model with p autoregressive terms, q moving average terms and b eXogenous inputs terms. This model contains the AR(p) and MA(q) models and a linear combination of the last b terms of a known and external time series d_t. It is given by:
where \eta_1, \ldots, \eta_b are the parameters of the exogenous input d_t.