Class ARMAMaxLikelihood
- All Implemented Interfaces:
Serializable
ARMAMaxLikelihood computes estimates of parameters for a
nonseasonal ARMA model given a sample of observations,
\(W_t\), for \(t=1, 2,\ldots, n, \) where
\(n=\)
z.length. The class 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.
The stationary time series \(W_t\)
with mean \(\mu\) can be represented by the nonseasonal
autoregressive moving average (ARMA) model by the following relationship:
$$ {\phi}(B)(W_t-\mu)=\theta(B)a_t$$
where $$ t{\in}Z, ~~
Z=\{\ldots,-2,-1,0,1,2,\ldots\}\rm{,}$$
B is the backward shift operator defined by
\(B^kW_t=W_{t-k}\rm{,}\)
$$
\phi(B)=1-{\phi_1}B-{\phi_2}{B^2}-\ldots-{\phi_p}{B^p}, ~ p \ge
0\rm{.}$$
and $$
\theta(B)=1-{\theta_1}B-{\theta_2}{B^2}-\ldots-{\theta_q}{B^q}, ~ q \ge
0\rm{.}$$
The ARMAMaxLikelihood class estimates the AR coefficients
\(\phi_1,\phi_2,\ldots,\phi_p\) and the MA coefficients
\(\theta_1,\theta_2,\ldots,\theta_p\) using maximum
likelihood estimation.
ARMAMaxLikelihood checks the initial estimates for both the
autoregressive and moving average coefficients to ensure that they represent
a stationary and invertible series respectively.
If $${\phi_1},{\phi_2},\ldots,{\phi_p}$$ are the initial estimates for a stationary series then all (complex) roots of the following polynomial will fall outside the unit circle: $$1-{\phi_1}z-{\phi_2}{z^2}-\ldots-{\phi_p}z^p\rm{.}$$
If $${\theta_1},{\theta_2},\ldots,{\theta_p}$$ are initial estimates for an invertible series then all (complex) roots of the polynomial $$1-{\theta_1}z-{\theta_2}{z^2}-\ldots-{\theta_q}z^q$$ will fall outside the unit circle.
By default, the order of the lags for the autoregressive terms is \(1, 2, \ldots, p\) and \(1, 2, \ldots, q\) for the moving average terms. However, this cannot be overridden.
Initial values for the AR and MA coefficients can
be supplied via the setAR and setMA methods.
Otherwise, initial estimates are computed internally by the method of
moments. The class computes the roots of the associated polynomials. If the
AR estimates represent a nonstationary series,
ARMAMaxLikelihood issues a warning message and replaces the
intial AR estimates with initial values that are stationary. If
the MA estimates represent a noninvertible series, a terminal
error is issued and new initial values must be sought.
ARMAMaxLikelihood 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 nonstationary solution. If
nonstationary estimates are encountered, a fatal error message is issued.
For model selection, the ARMA model with the minimum value for
AIC might be preferred,
\(\mbox{AIC} = -2\ln(L)+2(p+q)\), where L is the
value of the maximum likelihood function evaluated at the parameter
estimates.
ARMAMaxLikelihood can also handle white noise processes, i.e.
\(ARMA(0,0)\) processes.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe solution is noninvertible.static classThe solution is nonstationary. -
Constructor Summary
ConstructorsConstructorDescriptionARMAMaxLikelihood(int p, int q, double[] z) Constructor forARMAMaxLikelihood. -
Method Summary
Modifier and TypeMethodDescriptionvoidcompute()Computes the exact maximum likelihood estimates for the autoregressive and moving average parameters of an ARMA time seriesdouble[][]forecast(int nForecast) Returns forecasts for lead times \(l=1,2,\ldots,\rm{nForecast}\) at originsz.length-backwardOrigin-1+jwhere \(j=1,\ldots,\rm{backwardOrigin}+1\).double[]getAR()Returns the final autoregressive parameter estimates.intReturns the current value for forecasting backward origin.doubleReturns the confidence level used for calculating deviations ingetDeviations.doubleReturns the estimate for the constant parameter in the ARMA series.double[]Returns the deviations from each forecast used for calculating the forecast confidence limits.double[]getForecast(int nForecast) Returns forecastsdouble[]Returns the gradients for the final parameter estimates.doubleReturns the gradient tolerance for the convergence algorithm.doubleReturns the estimated innovation variance of this series.doubleReturns the final estimate for \(-2\ln(L)\), where \(L\) is equal to the likelihood function evaluated using the final parameter estimates.double[]getMA()Returns the final moving average parameter estimates.intReturns the maximum number of iterations.doublegetMean()Returns the mean used to center the time series.intgetP()Returns the number of autoregressive terms in the ARMA modeldouble[]Returns the psi weights used for calculating forecasts from the infinite order moving average form of the ARMA model.intgetQ()Returns the number of moving average terms in the ARMA modeldouble[]Returns the current values of the vector of residuals.double[]Returns the time series used to constructARMAMaxLikelihood.doubleReturns the tolerance for the convergence algorithm.booleanisInvertible(double[] ma) Tests whether the coefficients inmaare invertiblebooleanisStationary(double[] ar) Tests whether the coefficients inarare stationary.voidsetAR(double[] ar) Sets the initial values for the autoregressive terms to thepvalues inar.voidsetBackwardOrigin(int backwardOrigin) Sets the maximum backward origin.voidsetConfidence(double confidence) Sets the confidence level for calculating confidence limit deviations returned fromgetDeviations().voidsetConstant(double constant) Sets the initial value for the constant term in the ARMA model.voidsetGradientTolerance(double gradientTolerance) Sets the tolerance for the convergence algorithm.voidsetMA(double[] ma) Sets the initial values for the moving average terms to theqvalues inma.voidsetMaxIterations(int maxIterations) Sets the maximum number of iterations.voidsetMean(double wMean) Sets the mean used for centering the series.voidsetTolerance(double tolerance) Sets the tolerance for the convergence algorithm.
-
Constructor Details
-
ARMAMaxLikelihood
public ARMAMaxLikelihood(int p, int q, double[] z) throws ARMA.MatrixSingularException, ARMA.TooManyCallsException, ARMA.IncreaseErrRelException, ARMA.NewInitialGuessException, ARMA.IllConditionedException, ARMA.TooManyITNException, ARMA.TooManyFcnEvalException, ARMA.TooManyJacobianEvalException Constructor forARMAMaxLikelihood.- Parameters:
p- Anintscalar equal to the number of autoregressive (AR) parameters.q- Anintscalar equal to the number of moving average (MA) parameters.z- Adoublearray containing the time series.- Throws:
ARMA.MatrixSingularException- is thrown if the input matrix is singular.ARMA.TooManyCallsException- is thrown if the number of calls to the function has exceeded the maximum number of iterations times the number of moving average (MA) parameters + 1.ARMA.IncreaseErrRelException- is thrown if the bound for the relative error is too small.ARMA.NewInitialGuessException- is thrown if the iteration has not made good progress.ARMA.IllConditionedException- is thrown if the problem is ill-conditioned.ARMA.TooManyITNException- is thrown if the maximum number of iterations is exceeded.ARMA.TooManyFcnEvalException- is thrown if the maximum number of function evaluations exceeded.ARMA.TooManyJacobianEvalException- is thrown if the maximum number of Jacobian evaluations is exceeded.
-
-
Method Details
-
compute
public void compute() throws ARMAMaxLikelihood.NonStationaryException, ARMAMaxLikelihood.NonInvertibleExceptionComputes the exact maximum likelihood estimates for the autoregressive and moving average parameters of an ARMA time series- Throws:
ARMAMaxLikelihood.NonStationaryException- is thrown if the final maximum likelihood estimates for the time series are nonstationary.ARMAMaxLikelihood.NonInvertibleException- is thrown if the final maximum likelihood estimates for the time series are noninvertible.
-
setConfidence
public void setConfidence(double confidence) Sets the confidence level for calculating confidence limit deviations returned fromgetDeviations().- Parameters:
confidence- adoublescalar specifying the confidence level used in computing forecast confidence intervals. Typical choices forconfidenceare 0.90, 0.95, and 0.99.confidencemust be greater than 0.0 and less than 1.0. Default:confidence = 0.95.
-
getBackwardOrigin
public int getBackwardOrigin()Returns the current value for forecasting backward origin.- Returns:
- A
doublescalar value representing the current value ofbackwardOrigin
-
getConfidence
public double getConfidence()Returns the confidence level used for calculating deviations ingetDeviations.- Returns:
- A
doublescalar value ofconfidenceused for computing the(1-confidence)*100%forecast confidence interval.
-
getP
public int getP()Returns the number of autoregressive terms in the ARMA model- Returns:
- An
intscalar value ofp, the number of autoregressive terms in the ARMA model.
-
getQ
public int getQ()Returns the number of moving average terms in the ARMA model- Returns:
- An
intscalar value ofq, the number of moving average terms in the ARMA model.
-
getGradients
public double[] getGradients()Returns the gradients for the final parameter estimates.- Returns:
- A
doublearray of lengthp+qcontaining the gradients of the final parameter estimates.
-
getAR
public double[] getAR()Returns the final autoregressive parameter estimates.- Returns:
- A
doublearray of lengthpcontaining the final autoregressive parameter estimates.
-
setAR
public void setAR(double[] ar) Sets the initial values for the autoregressive terms to thepvalues inar.- Parameters:
ar- An inputdoublearray of lengthpcontaining the initial values for the autoregressive terms. If this method is not called, initial values are computed by method of moments in theARMAclass.
-
setBackwardOrigin
public void setBackwardOrigin(int backwardOrigin) Sets the maximum backward origin.- Parameters:
backwardOrigin- Anintscalar specifying the maximum backward origin used in forecasting.backwardOriginmust be greater than or equal to 0 and less than or equal toz.length - StrictMath.max(p, q). Default:backwardOrigin = 0.
-
getMA
public double[] getMA()Returns the final moving average parameter estimates.- Returns:
- A
doublearray of lengthqcontaining the final moving average parameter estimates.
-
setMA
public void setMA(double[] ma) Sets the initial values for the moving average terms to theqvalues inma.- Parameters:
ma- Adoublearray of lengthqcontaining the initial values for the moving average terms. If this method is not called, initial values are computed by method of moments in theARMAclass.
-
getConstant
public double getConstant()Returns the estimate for the constant parameter in the ARMA series.- Returns:
- A
doublescalar equal to the estimate for the constant parameter in the ARMA series.
-
getForecast
public double[] getForecast(int nForecast) throws ARMAMaxLikelihood.NonStationaryException, ARMAMaxLikelihood.NonInvertibleException, ARMA.MatrixSingularException, ARMA.TooManyCallsException, ARMA.IncreaseErrRelException, ARMA.NewInitialGuessException, ARMA.IllConditionedException, ARMA.TooManyITNException, ARMA.TooManyFcnEvalException, ARMA.TooManyJacobianEvalException Returns forecasts- Parameters:
nForecast- An inputintrepresenting the number of requested forecasts beyond the last value in the series.- Returns:
- A
doublearray containing thenForecast+backwardOriginforecasts. The firstbackwardOriginforecasts are one-step ahead forecasts for the lastbackwardOriginvalues in the series. The nextnForecastvalues in the returned series are forecasts for the next values beyond the series. - Throws:
ARMAMaxLikelihood.NonStationaryException- is thrown if the final maximum likelihood estimates for the time series are nonstationary.ARMAMaxLikelihood.NonInvertibleException- is thrown if the final maximum likelihood estimates for the time series are noninvertible.ARMAMaxLikelihood.InitialMAException- is thrown if the initial values provided for the moving average terms usingsetMAare noninvertible. In this case,ARMAMaxLikelihoodterminates and does not compute the time series estimates.ARMA.MatrixSingularException- is thrown if the input matrix is singular.ARMA.TooManyCallsException- is thrown if the number of calls to the function has exceeded the maximum number of iterations times the number of moving average (MA) parameters + 1.ARMA.IncreaseErrRelException- is thrown if the bound for the relative error is too small.ARMA.NewInitialGuessException- is thrown if the iteration has not made good progress.ARMA.IllConditionedException- is thrown if the problem is ill-conditioned.ARMA.TooManyITNException- is thrown if the maximum number of iterations is exceeded.ARMA.TooManyFcnEvalException- is thrown if the maximum number of function evaluations exceeded.ARMA.TooManyJacobianEvalException- is thrown if the maximum number of Jacobian evaluations is exceeded.
-
forecast
public double[][] forecast(int nForecast) throws ARMAMaxLikelihood.NonStationaryException, ARMAMaxLikelihood.NonInvertibleException, ARMA.MatrixSingularException, ARMA.TooManyCallsException, ARMA.IncreaseErrRelException, ARMA.NewInitialGuessException, ARMA.IllConditionedException, ARMA.TooManyITNException, ARMA.TooManyFcnEvalException, ARMA.TooManyJacobianEvalException Returns forecasts for lead times \(l=1,2,\ldots,\rm{nForecast}\) at originsz.length-backwardOrigin-1+jwhere \(j=1,\ldots,\rm{backwardOrigin}+1\).- Parameters:
nForecast- Anintscalar equal to the number of requested forecasts- Returns:
- a
doublematrix of dimensions ofnForecastbybackwardOrigin + 1containing the forecasts. The forecasts are for lead times \(l=1,2,\ldots,\rm{nForecast}\) at originsz.length-backwardOrigin-1+jwhere \(j=1,\ldots,\rm{backwardOrigin}+1\). - Throws:
ARMAMaxLikelihood.NonStationaryException- is thrown if the final maximum likelihood estimates for the time series are non-stationary.ARMAMaxLikelihood.NonInvertibleException- is thrown if the final maximum likelihood estimates for the time series are noninvertible.ARMAMaxLikelihood.InitialMAException- is thrown if the initial values provided for the moving average terms usingsetMAare noninvertible. In this case,ARMAMaxLikelihoodterminates and does not compute the time series estimates.ARMA.MatrixSingularException- is thrown if the input matrix is singular.ARMA.TooManyCallsException- is thrown if the number of calls to the function has exceeded the maximum number of iterations times the number of moving average (MA) parameters + 1.ARMA.IncreaseErrRelException- is thrown if the bound for the relative error is too small.ARMA.NewInitialGuessException- is thrown if the iteration has not made good progress.ARMA.IllConditionedException- is thrown if the problem is ill-conditioned.ARMA.TooManyITNException- is thrown if the maximum number of iterations is exceeded.ARMA.TooManyFcnEvalException- is thrown if the maximum number of function evaluations exceeded.ARMA.TooManyJacobianEvalException- is thrown if the maximum number of Jacobian evaluations is exceeded.
-
isStationary
public boolean isStationary(double[] ar) Tests whether the coefficients inarare stationary.- Parameters:
ar- Adoublearray containing the coefficients for the autoregressive terms in an ARMA model- Returns:
- A
booleanscalar equal totrueif the coefficients inarare stationary andfalseotherwise.
-
isInvertible
public boolean isInvertible(double[] ma) Tests whether the coefficients inmaare invertible- Parameters:
ma- Adoublearray containing the coefficients for the moving average terms in an ARMA model.- Returns:
- A
booleanscalar equal totrueif the coefficients inmaare invertible andfalseotherwise.
-
getLikelihood
public double getLikelihood() throws ARMAMaxLikelihood.NonStationaryException, ARMAMaxLikelihood.NonInvertibleExceptionReturns the final estimate for \(-2\ln(L)\), where \(L\) is equal to the likelihood function evaluated using the final parameter estimates.- Returns:
- A
doublescalar equal to the log likelihood function, \(-2\ln(L)\). - Throws:
ARMAMaxLikelihood.NonStationaryException- is thrown if the final maximum likelihood estimates for the time series are nonstationary.ARMAMaxLikelihood.NonInvertibleException- is thrown if the final maximum likelihood estimates for the time series are noninvertible.InitialMAException- is thrown if the initial values provided for the moving average terms usingsetMAare noninvertible. In this case,ARMAMaxLikelihoodterminates and does not compute the time series estimates.
-
getMaxIterations
public int getMaxIterations()Returns the maximum number of iterations.- Returns:
- An
intscalar containing the maximum number of iterations allowed in the nonlinear equation solver used in both the method of moments and least-squares algorithms. Default:maxIterations= 300.
-
getResiduals
public double[] getResiduals()Returns the current values of the vector of residuals.- Returns:
- A
doublearray of lengthbackwardOrigincontaining the residuals for the lastbackwardOriginvalues in the time series. Thecomputeand either theforecastorgetForecastmethods must be called before calling this method.
-
setMaxIterations
Sets the maximum number of iterations.- Parameters:
maxIterations- Anintscalar specifying the maximum number of iterations allowed in the nonlinear equation solver used in both the method of moments and least-squares algorithms. Default:maxIterations= 300.- Throws:
IllegalArgumentException
-
setConstant
public void setConstant(double constant) Sets the initial value for the constant term in the ARMA model.- Parameters:
constant- Adoublescalar specifying the initial value for the constant term in the ARMA model. By default, the constant term is initially estimated using ARMA method of moments estimation.
-
setMean
public void setMean(double wMean) Sets the mean used for centering the series.- Parameters:
wMean- Adoublescalar specifying the value to use for centering the time series. By default the series is centered using the mean of the series.
-
setTolerance
public void setTolerance(double tolerance) Sets the tolerance for the convergence algorithm.- Parameters:
tolerance- Adoublescalar specifying the value to use for the convergence tolerance. Default:tolerance = 2.220446049e-016.
-
getGradientTolerance
public double getGradientTolerance()Returns the gradient tolerance for the convergence algorithm.- Returns:
- A
doublescalar specifying the value used for the gradient tolerance.
-
setGradientTolerance
public void setGradientTolerance(double gradientTolerance) Sets the tolerance for the convergence algorithm.- Parameters:
gradientTolerance- Adoublescalar specifying the the tolerance used for numerically estimating the gradient by differences. Default:gradientTolerance = 1e-04.
-
getTolerance
public double getTolerance()Returns the tolerance for the convergence algorithm.- Returns:
- A
doublescalar containing the value of the tolerance used during maximum likelihood estimation.
-
getMean
public double getMean()Returns the mean used to center the time series.- Returns:
- A
doublescalar specifying the value to used for centering the time series.
-
getTimeSeries
public double[] getTimeSeries()Returns the time series used to constructARMAMaxLikelihood.- Returns:
- A
doublecontaining the values of the time series passed to the class constructor.
-
getInnovationVariance
public double getInnovationVariance()Returns the estimated innovation variance of this series.- Returns:
- A
doublescalar equal to the estimated innovation variance for the time series.
-
getDeviations
public double[] getDeviations()Returns the deviations from each forecast used for calculating the forecast confidence limits.- Returns:
- A
doublearray of lengthbackwardOrigin+nForecastcontaining the deviations for calculating forecast confidence intervals. The confidence level is specified inconfidence. By default,confidence= 0.95.
-
getPsiWeights
public double[] getPsiWeights()Returns the psi weights used for calculating forecasts from the infinite order moving average form of the ARMA model.- Returns:
- A
doublearray of lengthnForecastcontaining the psi weights of the infinite order moving average form of the model.
-