maxArma¶
Exact maximum likelihood estimation of the parameters in a univariate ARMA (autoregressive, moving average) time series model.
Synopsis¶
maxArma(w, p, q)
Required Arguments¶
- float
w[]
(Input) - Array of length
nObs
containing the time series. - int
p
(Input) - Non-negative number of autoregressive parameters.
- int
q
(Input) - Non-negative number of moving average parameters.
Return Value¶
An array of length 1+p
+q
with the estimated constant, AR and
MA parameters. If no value can be computed, None
is returned.
Optional Arguments¶
initialEstimates
, floatinitAr[]
, floatinitMa[]
(Input)- If specified,
initAr
is an array of lengthp
containing preliminary estimates of the autoregressive parameters, andinitMa
is an array of lengthq
containing preliminary estimates of the moving average parameters; otherwise, they are computed internally. If \(p=0\) or \(q=0\), then the corresponding arguments are ignored. printLevel
, int (Input)Printing options:
printLevel
Action 0 No Printing. 1 Prints final results only. 2 Prints intermediate and final results. Default:
printLevel
= 0.maxIterations
, int (Input)Maximum number of estimation iterations.
Default:
maxIterations
= 300varNoise
(Output)- Estimate of innovation variance.
logLikelihood
(Output)- Value of -2 × (ln(likelihood)) for the fitted model.
armaInfo
(Output)- A structure that contains information necessary in the call to
armaForecast
. meanEstimate
, float (Input/Output)Estimate of the mean of the time series
w
. On return,meanEstimate
contains an update of the mean.Default: Time series
w
is centered about its sample mean.residual
(Output)- An array of length
nObs
containing the residuals of the requested ARMA fit.
Description¶
The function maxArma
is derived from the maximum likelihood estimation
algorithm described by Akaike, Kitagawa, Arahata and Tada (1979), and the
XSARMA routine published in the TIMSAC-78 Library.
Using the notation developed in the Time Domain Methodology at the beginning of this chapter, the stationary time series \(W_t\) with mean \(\mu\) can be represented by the nonseasonal autoregressive moving average (ARMA) model by the following relationship:
where
B is the backward shift operator defined by \(B^k W_t=W_{t-k}\),
and
Function maxArma
estimates the AR coefficients
\(\phi_1,\phi_2,\cdots,\phi_p\) and the MA coefficients
\(\theta_1,\theta_2,\cdots,\theta_q\) using maximum likelihood
estimation.
Function maxArma
checks the initial estimates for both the
autoregressive and moving average coefficients to ensure that they represent
a stationary and invertible series respectively.
If
are the initial estimates for a stationary series then all (complex) roots of the following polynomial will fall outside the unit circle:
Initial values for the AR and MA coefficients can be supplied by vectors
initAr
and initMa
. Otherwise, estimates are computed internally by
the method of moments. maxArma
computes the roots of the associated
polynomials. If the AR estimates represent a non-stationary series,
maxArma
issues a warning message and replaces initAr
with initial
values that are stationary. If the MA estimates represent a non-invertible
series, maxArma
issues a terminal error, and new initial values have to
be sought.
maxArma
also validates the final estimates of the AR coefficients to
ensure that they too represent a stationary series. This is done to guard
against the possibility that the internal log-likelihood optimizer converged
to a non-stationary solution. If non-stationary estimates are encountered,
maxArma
issues a fatal error message.
For model selection, the ARMA model with the minimum value for AIC might be preferred,
Function maxArma
can also handle white noise processes, i.e. ARMA(0,0)
Processes.
Examples¶
Example 1¶
Consider the Wolfer Sunspot data (Anderson 1971, p. 660) consisting of the
number of sunspots observed each year from 1770 through 1869. In this
example, maxArma
is used to fit the following ARMA
(2
, 1
)
model:
with \(\tilde{w}_t :=w_t-\mu\), \(\mu\) the sample mean of the time series \(\left\{ w_t \right\}\).
For these data, maxArma
calculated the following model:
Defining the overall constant \(\phi_0\) by \(\phi_0 :=\mu\left( 1-\textstyle\sum_{i=1}^{p} \phi_i \right)\), we obtain the following equivalent representations:
and
from __future__ import print_function
from numpy import *
from pyimsl.stat.dataSets import dataSets
from pyimsl.stat.maxArma import maxArma
n_obs = 100
p = 2
q = 1
w = empty(100)
avar = []
log_likeli = []
# get wolfer sunspot data
z = dataSets(2)
for i in range(0, n_obs):
w[i] = z[21 + i][1]
parameters = maxArma(w, p, q,
maxIterations=12000,
varNoise=avar,
logLikelihood=log_likeli)
print("AR estimates are %11.4f and %11.4f" % (parameters[1], parameters[2]))
print("MA estimate is %11.4f" % parameters[3])
print("Constant estimate is %11.4f" % parameters[0])
print("-2*ln(Maximum Log Likelihood) = %11.4f" % log_likeli[0])
print("White noise variance = %11.4f" % avar[0])
Output¶
AR estimates are 1.2250 and -0.5605
MA estimate is -0.3830
Constant estimate is 15.7609
-2*ln(Maximum Log Likelihood) = 539.5838
White noise variance = 214.5088
Example 2¶
This example is the same as Example 1, but now initial values for the AR and MA parameters are explicitly given.
from __future__ import print_function
from numpy import *
from pyimsl.stat.dataSets import dataSets
from pyimsl.stat.maxArma import maxArma
n_obs = 100
p = 2
q = 1
w = empty(100)
avar = []
log_likeli = []
init_ar = (1.244e0, -0.575e0)
init_ma = (-0.1241e0)
# get wolfer sunspot data
z = dataSets(2)
for i in range(0, n_obs):
w[i] = z[21 + i][1]
parameters = maxArma(w, p, q,
maxIterations=12000,
varNoise=avar,
logLikelihood=log_likeli,
initialEstimates={'initAr': init_ar, 'initMa': init_ma})
print("AR estimates are %11.4f and %11.4f" % (parameters[1], parameters[2]))
print("MA estimate is %11.4f" % parameters[3])
print("Constant estimate is %11.4f" % parameters[0])
print("-2*ln(Maximum Log Likelihood) = %11.4f" % log_likeli[0])
print("White noise variance = %11.4f" % avar[0])
Output¶
AR estimates are 1.2250 and -0.5605
MA estimate is -0.3830
Constant estimate is 15.7609
-2*ln(Maximum Log Likelihood) = 539.5838
White noise variance = 214.5088