Next: mulvarhelp() Up: MacAnova Help File Previous: Mouse()   Contents


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

Keywords: time series
movavg() is designed to implement a moving average operator as the term
is used in ARIMA time series analysis.  For a more ordinary moving
average, convolve() is preferable.  movavg() can also be used to compute
differences of a series or, together with autoreg(), to find the power
series coefficients of rational functions.

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

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

When Theta is a vector, movavg(Theta,A) can be expressed in matrix terms
as Theta1 %*% A, where Theta1 is a nrows(A) by nrows(A) matrix.  For
example, when nrows(Theta) = 2,
         [   1          0        0       0   ...    0        0       0 ]
         [-Theta[1]     1        0       0   ...    0        0       0 ]
Theta1 = [-Theta[2] -Theta[1]    1       0   ...    0        0       0 ]
         [   0      -Theta[2] -Theta[1]  1   ...    0        0       0 ]
         [ ........................................................... ]
         [   0          0        0       0   ... -Theta[2] -Theta[1] 1 ]

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

If Theta 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 movavg(1,A), where A is a vector or matrix.  This
computes the first differences A[1,] - 0,A[2,]-A[1,], ...,A[n,]-A[n-1,].
Second differences can be computed by movavg(vector(2,-1),A), third
differences by movavg(vector(3, -3, 1), A), and so on.

movavg(Theta,A,reverse:T) applies the moving average operator in
    x[i] = A[i] - sum(Theta[k]*A[i+k],1<=k<=nrows(phi))
with A[l] = 0 for l > nrows(A).

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

movavg(Theta,A,limits:vector(i1,i2),start:StartVals [,reverse:T,
seasonal:L]) is the same except that x[i] is computed as just described
only for i1 <= i <= i2, with the remaining values copied from rows 1 to
i1-1 and rows i2+1 to nrows(A) of matrix StartVals.

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 are copied to the rows not included
between i1 and i2 and hence nrows(start) must match nrows(A) - (i2 - i1
+ 1).

Unlike what happens with autoreg(), the values computed for rows i1 to
i2 are unaffected by the values of StartVals.

Examples (theta and theta1 vectors of same length):
  Cmd> m <- nrows(theta); n <- 300
  Cmd> movavg(theta,rnorm(n+m))[-run(m)]
     generates a moving average series with normal innovations.
  Cmd> movavg(theta,matrix(rnorm(10*(n+m),10))[-run(m),]
     generates 10 independent moving average series
  Cmd> movavg(hconcat(theta,theta1),rnorm(n+m))[-run(m)]
     generates two moving average series with the same innovations
  Cmd> movavg(.3,movavg(-.1,rnorm(230),seasonal:4))[-run(30)] generates
      a (0,0,1)x(0,0,1)-4 seasonal ARMA time series

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

See also autoreg().

Gary Oehlert 2003-01-15