Next: batch() Up: MacAnova Help File Previous: attachnotes()   Contents

autoreg()

Usage:
autoreg(Phi,A [,reverse:T, limits:vector(i1 [,i2]), start:startVals,\
  seasonal:L]), REAL vector or NULL Phi, REAL vector or matrix A, REAL
  startVals the same size and shape as A, positive integer L



Keywords: time series
autoreg() is designed to implement an autoregressive operator as the
term is used in ARIMA time series analysis.  It can also be used to
compute partial sums of a series or, together with movavg(), to find the
power series coefficients of rational functions.

autoreg(Phi,A) applies the autoregressive operators specified by the
columns of the REAL matrix Phi to the columns of the REAL matrix A.
When ncols(Phi) = 1, Phi is applied to every column of A and if ncols(A)
= 1, each column of Phi is applied to A.  The result is a matrix with
nrows(A) rows and max(ncols(Phi), ncols(A)) columns.  When both Phi and
A have more than one column, they must both have the same number of
columns.

Specifically, assuming for simplicity that both Phi and A are vectors so
that the result x is a vector,
    x[i] = A[i] + sum(Phi[k]*x[i-k],1<=k<=nrows(Phi)),
with x[l] taken to be 0 for l < 1.

When Phi is a vector, movavg(Phi,A) can be expressed in matrix terms as
solve(Phi1, A), where Phi1 is a nrows(A) by nrows(A) matrix.  For
example, when nrows(Phi) = 2,
         [   1        0        0       0   ...    0        0       0 ]
         [-Phi[1]     1        0       0   ...    0        0       0 ]
  Phi1 = [-Phi[2]  -Phi[1]     1       0   ...    0        0       0 ]
         [   0     -Phi[2]  -Phi[1]    1   ...    0        0       0 ]
         [ ......................................................... ]
         [   0        0        0       0   ... -Phi[2]  -Phi[1]    1 ]
See also solve().

NOTE: The sign assumed for Phi is not affected by variable ARSIGN which
is recognized by several macros in file Arima.mac.  Type
arimahelp(MASIGN) for details.

When Phi is NULL, the result is the same as A, stripped of labels or
notes, if any.  Also, the result is a true vector or matrix (ndims = 1
or 2).

A common usage is autoreg(1,x), where x is a vector or matrix.  This
computes the partial sums x[1,], x[1,]+x[2,], ..., sum(x).  A useful
macro might be defined by
    partialsum <- matrix("autoreg(1,$1)")

autoreg(Phi,A,reverse:T) applies the autoregressive operator in reverse:
    x[i] = A[i] + sum(Phi[k]*x[i+k],1<=k<=nrows(Phi)),
with x[l] = 0 for l > nrows(A).

autoreg(Phi,A,seasonal:L [,reverse:T) does the same, except that the
computations are of the forms
    x[i] = A[i] + sum(Phi[k]*x[i-k*L],1<=k<=nrows(Phi)).
or
    x[i] = A[i] + sum(Phi[k]*x[i+k*L],1<=k<=nrows(Phi)) (reverse:T)

autoreg(Phi,A,limits:vector(i1,i2),start:StartVals [,reverse:T,
seasonal:L]) is the same except that x[i] is computed as described only
for i1 <= i <= i2, with the remaining values copied before the
computation from rows 1 to i1-1 and rows i2+1 to nrows(A) of matrix
StartVals.  The values in rows 1 through i1-1 of StartVals serve as
"starting values" for the autoregressive operator.  When reverse:T is an
argument, rows nrows(A) through i2+1 serve as starting values.  This
feature is useful for generating out of sample forecasts or "backcasts".

The value for limits can also be a scalar j between 1 and nrows(A).  In
this case, with reverse:T, i1 = 1, i2 = j, and without reverse:T, i1 = j,
i2 = nrows(A).

StartVals must have the same number of columns as A and usually has the
same number of rows.  When nrows(StartVCals) != nrows(A), without
reverse:T, i2 must be nrows(A) and with reverse:T, i1 must be 1.  In
this case, the elements of StartVals, which are used as starting values,
are copied to the rows not included between i1 and i2 and hence
nrows(start) must match nrows(A) - (i2 - i1 + 1).  This feature allows
you to compute autoregressive predictions up to 20 time units ahead,
say, by
  Cmd> autoreg(phi,rep(0,length(x) + 20),limits:length(x)+1,start:x)

autoreg() is the inverse of movavg() and vice versa, in that
   autoreg(phi,movavg(phi,x))  and   movavg(phi,autoreg(phi,x))
both reproduce x, except for rounding error.

Examples:
  Cmd> autoreg(phi,rnorm(400))[-run(100)]
    generates an autoregressive series with normal innovations,
    discarding the first 100 values to avoid transients.
  Cmd> autoreg(phi,matrix(rnorm(4000),400)[-run(100),]
    generates 10 independent autoregressive series at once.
  Cmd> autoreg(hconcat(phi1,phi2),rnorm(400))[-run(100)]
    generates 2 autoregressive series with different coefficients but
    the same innovations
  Cmd> autoreg(.3, autoreg(-.1,rnorm(230),seasonal:4))[-run(30)]
     generates a (1,0,0)x(1,0,0)-4 seasonal ARMA time series
  Cmd> autoreg(vector(1,1),padto(1,20))
     computes the first 20 Fibonacci numbers F(j) satisfying F(j) =
     F(j-1) + F(j-2) with F(1) = 1, F(0) = 0

See also movavg().


Gary Oehlert 2003-01-15