HannanRissanen—Procedure for HR algorithm
Posted: Wed Feb 25, 2009 12:46 pm
This is a procedure for estimating an ARMA model using the Hannan-Rissanen algorithm. This is a quick two (or three) step procedure for getting estimates for a basic ARMA model. With the speed of modern computers, it's not clear how useful it is (compared with just iterating BOXJENK to convergence), but we provide it since it's sometimes described in textbooks.
Code: Select all
*
* @HannanRissanen( options ) series start end
*
* Computes estimates for an ARMA model using the Hannan-Rissanen algorithm, which
* runs a LS regression on lags of the dependent variable and residuals from a
* long preliminary AR.
*
* Parameters:
* series Series to analyze
* start end Range to analyze [range of series]
*
* Options
* AR=number of AR parameters [0]
* MA=number of MA parameters [0]
* DIFF=number of regular differencings[0]
* SDIFFS=number of seasonal differencings[0]
* M=number of lags in the long preliminary AR. By default, this uses the
* Gomez proposal of max(log**2(T),2*max(p,q))
* METHOD=[YULE]/BURG
* Method used in computing the long AR
* [CORRECTION]/NOCORRECTION
* Chooses whether or not to do a one-step correction to the initial estimates.
* [PRINT]/NOPRINT
* DEFINE=equation to define
*
* References:
* Hannan and Rissanen, "Recursive estimation of mixed autoregressive-moving average order",
* Biometrika, 1991, vol 69, pp 81-94.
*
* Gomez and Maravall, "Automatic Modeling Methods for Univariate Series", in
* Peña, Tiao and Tsay, eds., "A Course in Time Series Analysis", New York: Wiley, 2001.
*
procedure HannanRissanen series start end
type series series
type integer start end
*
option integer ar 0
option integer ma 0
option integer diffs 0
option integer sdiffs 0
option integer m
option switch correction 1
option choice method 1 yule burg
option switch print 1
option equation *define
*
local integer startl endl lags nobs skips span
local series xc e v w
local real value
local equation armaeq
local vector beta0
*
if .not.%defined(series) {
disp "Syntax: @HannanRissanen(options) SERIES start end"
return
}
compute span=2:1-1:1
inquire(series=series) startl<<start endl<<end
compute startl=startl+diffs+sdiffs*span
diff(diffs=diffs,sdiffs=sdiffs,center) series startl endl xc
compute nobs=endl-startl+1
*
* By default, use Gomez proposal for lags in the AR
*
if .not.%defined(m)
compute lags=%imax(fix(log(nobs)^2),2*%imax(ar,ma))
else
compute lags=%imax(m,%imax(ar,ma))
*
* Compute the long AR
*
@DurbinLevinson(m=lags,method=method) series startl endl
*
set e startl endl = %if(t<startl+lags,0.0,%(value=xc,%do(j,1,lags,value=value-%beta(j)*xc{j}),value))
*
* If we're doing a correction step, use the data range that will be used in
* the correction step. This includes some extra zeros.
*
if correction
compute skips=%imax(ar,ma)
else
compute skips=lags+ma
linreg(define=armaeq,noprint) xc startl+skips endl
# xc{1 to ar} e{1 to ma}
compute beta0=%beta
*
* If <<correction>>, do one step of a Gauss-Newton algorithm on the maximum sample
* size that can be done by a LS regression. The definition of <<v>> below (which
* generates the derivatives with respect to the AR parameters) is more accurate than
* what is described in (e.g.) Gomez and Maravall. This, in fact, gives the exact
* derivatives of the <<e>> series as generated below with respect to the AR parameters.
*
if correction {
set e startl endl = %if(t<startl+skips,0.0,xc-%dot(%beta,%eqnxvector(armaeq,t)))
*
*set v startl endl = %if(t<startl+skips,0.0,%(value=e,%do(j,1,ar,value=value+%beta( j)*v{j}),-value))
set v startl endl = value=xc,%do(j,1,ma,value=value+%beta(ar+j)*%if(t-j<startl,0,v{j})),-value
set w startl endl = %if(t<startl+skips,0.0,%(value=e,%do(j,1,ma,value=value+%beta(ar+j)*w{j}),-value))
*
linreg(noprint) e startl+skips endl
# v{1 to ar} w{1 to ma}
compute %beta=beta0-%beta
}
*
modify armaeq define
if print {
disp
disp "Equation Estimated by Hannan-Rissanen"
}
vreplace(print=print) e with %mvgavge
end