compose.ar1 {mar1s}R Documentation

Compose and Decompose AR(1) Process

Description

compose.ar1 composes AR(1) process realization by given vector(s) of innovations.

decompose.ar1 extracts AR(1) process residuals from time series.

Usage

compose.ar1(arcoef, innov, init = 0, xregcoef = 0, xreg = NULL,
            init.xreg = rep(0, length(xregcoef)))

decompose.ar1(arcoef, data, init = NA, xregcoef = 0, xreg = NULL,
              init.xreg = rep(NA, length(xregcoef)))

Arguments

arcoef A number specifying autoregression coefficient.
innov A univariate or multivariate time series containing the innovations.
data A univariate or multivariate time series containing the process realization(s).
init A number specifying the value of the process just prior to the start value in innov/data.
xregcoef A vector specifying coefficients for the external regressors.
xreg A matrix-like object of the same row count as innov/data, specifying the values of external regressors. The default NULL means zeroes.
init.xreg A vector specifying the values of external regressors just prior to the start values in xreg. The default NULL means zeroes.

Details

Here AR(1) process with external regressors is a linear regresson with AR(1) model for the error term:

y[t] = b[1]*x[t, 1] + ... + b[k]*x[t, k] + z[t]

z[t] = a*z[t-1] + e[t]

Use xreg = NULL for the regular AR(1) process.

Value

An object of the same type and dimensions as innov/data (typically time series).

See Also

arima for more general ARMA(p, q) processes.

Examples

## Simple
e <- ts(c(0, 1, 0, 1, 0), freq = 12)
compose.ar1(0.1, e)
compose.ar1(0.1, e, 1)

x <- ts(c(0, 1, 0, 1, 0), freq = 12)
decompose.ar1(0.1, x)
decompose.ar1(0.1, x, 1)

## Multiseries
compose.ar1(0.1, ts(cbind(0, 1)))
compose.ar1(0.1, ts(cbind(c(0, 1, 0), c(1, 0, 1))))

decompose.ar1(0.1, ts(cbind(0, 1)))
decompose.ar1(0.1, ts(cbind(c(0, 1, 0), c(1, 0, 1))))

## External regressors
xreg1 <- rep(2, 5)
xreg2 <- matrix(rep(c(2, 1), each = 5), 5, 2)
e <- ts(c(0, 1, 0, 1, 0), freq = 12)
compose.ar1(0.1, e, xregcoef = 0.5, xreg = xreg1)
compose.ar1(0.1, e, xregcoef = 0.5, init = 0, xreg = xreg1, init.xreg = -2)
compose.ar1(0.1, e, xregcoef = c(1, -1), xreg = xreg2)

x <- ts(c(0, 1, 0, 1, 0), freq = 12)
decompose.ar1(0.1, x, xregcoef = 0.5, xreg = xreg1)
decompose.ar1(0.1, x, xregcoef = 0.5, init = 0, xreg = xreg1, init.xreg = -2)
decompose.ar1(0.1, x, xregcoef = c(1, -1), xreg = xreg2)

## Back-test
a <- 0.5
innov <- ts(rnorm(10), frequency = 12)
init <- 1
xrcoef <- seq(-0.1, 0.1, length.out = 3)
xreg <- matrix(1:30, 10, 3)
init.xreg <- 1:3
x <- compose.ar1(a, innov, init, xrcoef, xreg, init.xreg)
r <- decompose.ar1(a, x, init, xrcoef, xreg, init.xreg)
stopifnot(all.equal(innov, r))

[Package mar1s version 2.0-1 Index]