compose.ar1: Compose and Decompose AR(1) Process

Description Usage Arguments Details Value See Also Examples

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

1
2
3
4
5
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:

\code{y[t] = b[1]*x[t, 1] + … + b[k]*x[t, k] + z[t]}

\code{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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## 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))

Example output

Loading required package: cmrutils
Loading required package: chron
Loading required package: fda
Loading required package: splines
Loading required package: Matrix
Loading required package: fds
Loading required package: rainbow
Loading required package: MASS
Loading required package: pcaPP
Loading required package: RCurl

Attaching package:fdaThe following object is masked frompackage:graphics:

    matplot

Loading required package: zoo

Attaching package:zooThe following objects are masked frompackage:base:

    as.Date, as.Date.numeric

    Jan   Feb   Mar   Apr   May
1 0.000 1.000 0.100 1.010 0.101
      Jan     Feb     Mar     Apr     May
1 0.10000 1.01000 0.10100 1.01010 0.10101
   Jan  Feb  Mar  Apr  May
1   NA  1.0 -0.1  1.0 -0.1
   Jan  Feb  Mar  Apr  May
1 -0.1  1.0 -0.1  1.0 -0.1
Time Series:
Start = 1 
End = 1 
Frequency = 1 
  Series 1 Series 2
1        0        1
Time Series:
Start = 1 
End = 3 
Frequency = 1 
  Series 1 Series 2
1      0.0     1.00
2      1.0     0.10
3      0.1     1.01
Time Series:
Start = 1 
End = 1 
Frequency = 1 
  Series 1 Series 2
1       NA       NA
Time Series:
Start = 1 
End = 3 
Frequency = 1 
  Series 1 Series 2
1       NA       NA
2      1.0     -0.1
3     -0.1      1.0
    Jan   Feb   Mar   Apr   May
1 1.000 2.000 1.100 2.010 1.101
      Jan     Feb     Mar     Apr     May
1 1.10000 2.01000 1.10100 2.01010 1.10101
    Jan   Feb   Mar   Apr   May
1 1.000 2.000 1.100 2.010 1.101
   Jan  Feb  Mar  Apr  May
1   NA  0.1 -1.0  0.1 -1.0
   Jan  Feb  Mar  Apr  May
1 -1.1  0.1 -1.0  0.1 -1.0
   Jan  Feb  Mar  Apr  May
1   NA  0.1 -1.0  0.1 -1.0

mar1s documentation built on May 2, 2019, 3:40 p.m.

Related to compose.ar1 in mar1s...