ARMA Function
Computes method-of-moments or least-squares estimates of parameters for a nonseasonal ARMA model.
Usage
result = ARMA(z, p, q)
Input Parameters
z—One-dimensional array containing the observations.
p—Number of autoregressive parameters.
q—Number of moving average parameters.
Returned Value
result—An array of length 1 + p + q with the estimated constant, AR, and MA parameters. If No_Constant is specified, the 0-th element of this array is 0.0.
Input Keywords
Double—If present and nonzero, double precision is used.
No_ConstantIf present and nonzero, the time series is not centered about its mean. Keywords No_Constant and Constant cannot be used together.
Constant—If present and nonzero, the time series is centered about its mean. Keywords No_Constant and Constant cannot be used together.
Ar_Lags—One-dimensional array of length p containing the order of the nonzero autoregressive parameters. The elements of Ar_Lags must be greater than or equal to 1. Default: Ar_Lags = [1, 2, ..., p]
Ma_Lags—One-dimensional array of length q containing the order of the nonzero moving average parameters. The elements of Ma_Lags must be greater than or equal to 1. Default: Ma_Lags = [1, 2, ..., q]
MomentsIf present and nonzero, the autoregressive and moving average parameters are estimated by a method-of-moments procedure. Keywords Moments and Lsq cannot be used together. (Default)
Lsq—If present and nonzero, the autoregressive and moving average parameters are estimated by a least-squares procedure. Keywords Moments and Lsq cannot be used together.
Lgth_Backcast—Specifies the maximum length of backcasting. Must be greater than or equal to zero. Keywords Lgth_Backcast and Tol_Backcast must be used together. Default: Lgth_Backcast = 10
Tol_Backcast—Specifies the tolerance level used to determine convergence of the backcast algorithm. Typically, Tol_Backcast is set to a fraction of an estimate of the standard deviation of the time series. Keywords Lgth_Backcast and Tol_Backcast must be used together. Default: Tol_Backcast = 0.01 × standard deviation of l
Tol_Convergence—Tolerance level used to determine convergence of the nonlinear least-squares algorithm. Keyword Tol_Convergence represents the minimum relative decrease in sum of squares between two iterations required to determine convergence. Hence, Tol_Convergence must be greater than or equal to zero. Default: max {10–10, ε2 / 3} for single precision,
max {10–20, ε2 / 3} for double precision, where ε is machine precision.
Err_Rel—Stopping criterion for use in the nonlinear equation solver used in both the method-of-moments and least-squares algorithms. Default: Err_Rel = 100 × ε, where ε is machine precision
Itmax—Maximum number of iterations allowed in the nonlinear equation solver used in both the method-of-moments and least-squares algorithms. Default: Itmax = 200
Mean_Est—Initial estimate of the mean of the time series z.
Default:
Init_Est_Ar—Array of length p containing preliminary estimates of the autoregressive parameters, internally. Keywords Init_Est_Ar and Init_Est_Ma must be used together and are only applicable if Lsq is also present and nonzero.
Init_Est_Ma—Array of length q containing preliminary estimates of the moving average parameters. Keywords Init_Est_Ar and Init_Est_Ma must be used together and are only applicable if Lsq is also present and nonzero.
The following keywords are used to forecast up to N_Predict steps ahead and the information necessary to obtain confidence intervals:
N_Predict—Maximum lead time for forecasts. Keyword N_Predict must be greater than zero. Keywords Forecast and N_Predict must be used together.
Confidence—Value in the exclusive interval (0, 100) used to specify the confidence level of the forecasts. Typical choices for Confidence are 90.0, 95.0, and 99.0. Default: Confidence = 95.0
Backward_Origin—Maximum backward origin. Keyword Backward_Origin must be greater than or equal to zero and less than or equal to N_ELEMENTS(z) – (max(maxar, maxma)), where maxar = max(Ar_Lags) and maxma = max(Ma_Lags).
Forecasts at origins N_ELEMENTS(z) – Backward_Origin through N_ELEMENTS(z) are generated. Default: Backward_Origin = 0
Output Keywords
Residual—Named variable into which an array of length N_ELEMENTS(z) – (max(Ar_Lags)) + Lgth_Backcast containing the residuals (including backcasts) at the final parameter estimate point in the first N_ELEMENTS(z) – (max(Ar_Lags)) + nb, where nb is the number of values backcast is stored.
Param_Est_Cov—Named variable into which an array, containing the covariance matrix of the final parameter estimates, is stored. The array is of size np × np, where np = p + q + 1 if z is centered about its mean and np = p + q if z is not centered. The ordering of variables in Param_Est_Cov is Mean_Est, Ar_lags, and Ma_lags.
Autocov—Named variable into which an array of length p + q + 2 containing the variance and autocovariances of the time series z is stored. Keyword Autocov(0) contains the variance of the series z. Keyword Autocov(k) contains the autocovariance of lag k, where k = 0, 1, ..., p + q + 1.
Ss_Residual—Named variable into which the sum of squares of the random error is stored.
Forecast—Named variable into which an array of length N_Predict × (Backward_Origin + 3) containing the forecasts up to N_Predict steps ahead and the information necessary to obtain confidence intervals is stored. Keywords Forecast and N_Predict must be used together.
Discussion
Function ARMA computes estimates of parameters for a nonseasonal ARMA model given a sample of observations, {Zt}, for t = 1, 2, ..., n, where n = N_ELEMENTS(z). The user may choose either method of moments or least squares. The default is method of moments.
The user chooses the method-of-moments algorithm with the keyword Moments. The least-squares algorithm is used if Lsq is specified. If the user wishes to use the least-squares algorithm, the preliminary estimates are the method-of-moments estimates by default; otherwise, the user can input initial estimates by specifying keywords Init_Est_Ar and Init_Est_Ma. Table 9-1: Method-of-Moments and Least-Squares Keywords lists the appropriate keywords for both the method-of-moments and least-squares algorithm:
 
Method-of-Moments and Least-Squares Keywords
Method of
Moments
only
Least Squares only
Both Method of
Moments and
Least Squares
Moments
Lsq
Err_Rel
 
Constant (or No_Constant)
Itmax
 
Ar_Lags
Mean_Estimate
 
Ma_Lags
Autocov
 
Lgth_Backcast
Forecast
 
Tol_Backcast
N_Predict
 
Tol_Convergence
Confidence
 
Init_Est_Ar
Backward_Origin
 
Init_Est_Ma
 
 
Residual
 
 
Param_Est_Cov
 
 
Ss_Residual
 
Method-of-moments Estimation
Suppose the time series {Zt } is generated by an ARMA(p, q) model of the form:
for
Let
be the estimate of the mean μ of the time series {Zt}, where:
equals the following:
The autocovariance function is estimated by:
for k = 0, 1, ..., K, where K = p + q + 1. Note that:
is an estimate of the sample variance.
Given the sample autocovariances, the function computes the method-of-moments estimates of the autoregressive parameters using the extended Yule-Walker equations as follows:
where:
The overall constant θ0 is estimated by the following:
The moving average parameters are estimated based on a system of nonlinear equations given K = p + q + 1 autocovariances, σ(k) for k = 1, ..., K, and p autoregressive parameters φi for i = 1, ..., p.
Let Z't = φ(B)Zt. The autocovariances of the derived moving average process Z't = θ(B)At are estimated by the following relation:
The iterative procedure for determining the moving average parameters is based on the relation:
where σ(k) denotes the autocovariance function of the original Zt process.
Let τ = (τ0, τ1, ..., τq)T, f = (f0, f1, ..., fq)T, and T be a (q + 1) × (q + 1) matrix, where τj , fj , and T are as follows:
and:
Then, the value of τ at the (i + 1)-th iteration is determined by:
τ i + 1 = τ i – (T i)–1 f i
The estimation procedure begins with the initial value:
and terminates at iteration i when either |f i| is less than Err_Rel or i equals Itmax. The moving average parameter estimates are obtained from the final estimate of τ by setting:
for j = 1, ..., q. The random error variance is estimated by the following:
See Box and Jenkins (1976, pp. 498–500) for a description of a function that performs similar computations.
Least-squares Estimation
Suppose the time series {Zt } is generated by a nonseasonal ARMA model of the form:
where B is the backward-shift operator, μ is the mean of Zt , and:
with p autoregressive and q moving average parameters. Without loss of generality, the following is assumed:
so that the nonseasonal ARMA model is of order (p', q'), where:
and
Note that the usual hierarchial model assumes the following:
Consider the sum-of-squares function:
where:
and T = Lgth_Backcast is the length of backcasting from the beginning of the series. The random errors {At } are assumed to be independent and identical distributed N(0, σA2) random variables. Hence, the log-likelihood function is given by:
where f (μ, φ, θ) is a function of μ, φ, and θ.
For T = 0, the log-likelihood function is conditional on the past values of both Zt and At required to initialize the model. The method of selecting these initial values usually introduces transient bias into the model (Box and Jenkins 1976, pp. 210–211). For T = infinity, this dependency vanishes, and the estimation problem concerns maximization of the unconditional log-likelihood function. Box and Jenkins (1976, p. 213) argue that:
dominates
The parameter estimates that minimize the sum-of-squares function are called least-squares estimates. For large n, the unconditional least-squares estimates are approximately equal to the maximum likelihood-estimates.
In practice, a finite value of T enables sufficient approximation of the unconditional sum‑of‑squares function. The values of [At] needed to compute the unconditional sum of squares are computed iteratively with initial values of Zt obtained by backcasting. The residuals (including backcasts), estimate of random error variance, and covariance matrix of the final parameter estimates also are computed. ARIMA parameters can be computed using the DIFFERENCE Function, together with ARMA.
Forecasting Option
The Box-Jenkins forecasts and their associated confidence intervals for a nonseasonal ARMA model are computed given a sample of n = N_ELEMENTS(z) {Zt} for t = 1, 2, ..., n.
Suppose the time series {Zt} is generated by a nonseasonal ARMA model of the form:
φ (B) Zt = θ0 + θ (B) At
for
where B is the backward-shift operator, θ0 is the constant, and:
with p autoregressive and q moving average parameters. Without loss of generality, the following is assumed:
so that the nonseasonal ARMA model is of order (p', q'), where:
and
Note that the usual hierarchial model assumes the following:
The Box-Jenkins forecast at origin t for lead time l of Zt + l is defined in terms of the difference equation:
where the following is true:
The 100(1 – α)-percent confidence interval for Zt + l is given by:
where
is the 100 (1 – α / 2)-percentile of the standard normal distribution, σA is the standard deviation of the random error, and ψj is defined as follows:
In this equation, φi = 0 for i > p and θj = 0 for j > q. Note that the forecasts are computed for lead times l = 1, 2, ..., L at origins t = (nb), (nb + 1), ..., n, where L = N_Predict and b = Backward_Origin.
The Box-Jenkins forecasts minimize the mean-square error:
Also, the forecasts are easily updated according to the following equation:
This approach and others are discussed in Chapter 5 of Box and Jenkins (1976).
Example 1
Consider the Wolfer Sunspot Data (Anderson 1971, p. 660) consisting of the number of sunspots observed each year from 1749 through 1924. The data set for this example consists of the number of sunspots observed from 1770 through 1869 and is shown in Figure 9-1: Wolfer Sunspot Data Plot. The method-of-moments estimates:
, and
for the ARMA(2,1) model are:
where Zt is “raw” data and the errors At are independently and identical normally distributed with mean zero and variance σ2A.
; Get the Wolfer Sunspot Data.
temp = STATDATA(2)
; Use only 100 observations, 1770-1869.
z = TEMP(21:120, 1)
years = FINDGEN(100) + 1770
; Plot the data.
PLOT, years, z, XStyle = 1, Psym   = -6, $
   Title  = 'Wolfer Sunspot Data', XTitle = 'Year', $
   YTitle = 'Number of Sunspots'
p = 2
q = 1
; Perform time-series analysis.
parameters = ARMA(z, p, q)
PRINT, 'AR estimates:', parameters(1), parameters(2)
; PV-WAVE prints: AR estimates: 1.24426 -0.575149
PRINT, 'MA estimate :', parameters(3)
; PV-WAVE prints: MA estimate : -0.124094
 
Figure 9-1: Wolfer Sunspot Data Plot
Example 2
The data for this example are the same as that for the initial example. Preliminary method‑of‑moments estimates are computed by default, and the method of least squares is used to find the final estimates.
; Get the Wolfer Sunspot Data.
temp = STATDATA(2)
; Use only 100 observations, 1770-1869.
z = TEMP(21:120, 1)
; Perform time-series analysis using method of moments. The
; warning error can be ignored in this case.
parameters = ARMA(z, 2, 1, /Lsq, Tol_Convergence = .125) 
PRINT, 'AR estimates:', parameters(1), parameters(2)
; PV-WAVE prints: AR estimates: 1.39257 -0.732948
PRINT, 'MA estimate :', parameters(3)
; PV-WAVE prints: MA estimate : -0.137512
Example 3
Consider the Wolfer Sunspot Data (Anderson 1971, p. 660) consisting of the number of sunspots observed each year from 1749 through 1924. The data set for this example consists of the number of sunspots observed from 1770 through 1869. Function ARMA computes forecasts and 95-percent confidence limits for the forecasts for an ARMA(2, 1) model fit using function ARMA with the method‑of‑moments option. With Backward_Origin = 3, columns zero through three of Forecast provide forecasts given the data through 1866, 1867, 1868, and 1869. Column five gives the deviations from the forecast for computing confidence limits, and column six gives the psi weights, which can be used to update forecasts when more data is available. For example, the forecast for the 102-nd observation (year 1871) given the data through the 100-th observation (year 1869) is 77.21; 95-percent confidence limits are given by:
After observation 101 (Z101 for year 1870) is available, the forecast can be updated by using:
with the psi weight (ψ1 = 1.37) and the one-step-ahead forecast error for observation 101 (Z101 – 83.72) to give the following:
77.21 + 1.37 × (Z101 – 83.72)
Since this updated forecast is one step ahead, the 95-percent confidence limits are now given by the forecast:
First, define a procedure to output the results:
PRO print_results, parameters, forecast
   PRINT, 'Method-of-moments initial estimates:'
   PRINT, 'AR estimates:', parameters(1), parameters(2)
   PRINT, 'MA estimate :', parameters(3)
   PRINT
   lead_time = INDGEN(12) + 1
   forecast = [[lead_time], [forecast]]
   PRINT, 'Forecasts from ...'
   PRINT, 'lead time', ' 1866', ' 1867', $
      ' 1868', ' 1869', ' Deviat.', ' Psi'
   PM, forecast, Format = '(i6, 3x, 6f9.4)'
END
; Get the Wolfer Sunspot Data.
temp = STATDATA(2)
; Use only 100 observations, 1770-1869.
z = TEMP(21:120, 1)
; Perform time-series analysis using method-of-moments.
parameters = ARMA(z, 2, 1, Itmax = 0, Err_Rel = 0.0, $
   Forecast = forecast, N_Predict = 12, Backward_Origin = 3)
print_results, parameters, forecast
; PV-WAVE prints the following:
; Method-of-moments initial estimates:
;   AR estimates:      1.24426    -0.575149
;   MA estimate :    -0.124094
; Forecasts from ...
; lead time  1866     1867     1868     1869     Deviat.   Psi
;    1     18.2833  16.6151  55.1893  83.7196  33.2179   1.3684
;    2     28.9182  32.0189  62.7606  77.2092  56.2980   1.1274
;    3     41.0101  45.8275  61.8922  63.4608  67.6168   0.6158
;    4     49.9387  54.1496  56.4571  50.0987  70.6432   0.1178
;    5     54.0937  56.5623  50.1939  41.3803  70.7515  -0.2076
;    6     54.1282  54.7780  45.5268  38.2174  71.0869  -0.3261
;    7     51.7815  51.1701  43.3221  39.2965  71.9074  -0.2863
;    8     48.8417  47.7072  43.2631  42.4582  72.5337  -0.1687
;    9     46.5335  45.4736  44.4577  45.7715  72.7498  -0.0452
;   10     45.3524  44.6861  45.9781  48.0758  72.7653   0.0407
;   11     45.2103  44.9909  47.1827  49.0371  72.7779   0.0767
;   12     45.7128  45.8230  47.8072  48.9080  72.8225   0.0720
years = INDGEN(100) + 1770
; Plot data with forecasted values with confidence intervals.
PLOT, years, z, Psym   = -6, Symsize = .5, XStyle = 1, $
   XRange = [1770, 1885], YRange = [-50, 175], $
   Title  = 'Wolfer Sunspot Data', XTitle = 'Year', $
   YTitle = 'Number of Sunspots'
OPLOT, INDGEN(10) + 1870, forecast(*, 3), Psym   = 4, Symsize = .5
ERRPLOT, indgen(10) + 1870, forecast(*, 3) - forecast(*, 4), $
   forecast(*, 3) + forecast(*, 4), Width  = .005
The plot of the forecasts and the confidence limits from year 1869 are shown in Figure 9-2: Sunspot Data with Predicted Values and Confidence Bands.
 
Figure 9-2: Sunspot Data with Predicted Values and Confidence Bands