Skip to contents

Compute autocovariances of ARMA models and crosscovariances between an ARMA process and its innovations.

Usage

armaccf_xe(model, lag.max = 1)
armaacf(model, lag.max, compare)

Arguments

model

the model, a list with components ar, ma and sigma2 (for the time being, sigmasq is also accepted, if model$sigma2 is NULL).

lag.max

maximal lag for the result.

compare

if TRUE compute the autocovariances also using tacvfARMA() and return both results for comparison.

Details

Given a causal ARMA model, armaccf_xe computes theoretical crosscovariances \(R_{xe}(0)\), \(R_{xe}(1)\), \(R_{xe}(lag.max)\), where \(R_{xe}(k)=E(X_{t}e_{t-k})\), between an ARMA process and its innovations. Negative lags are not considered since \(R_{xe}(k)=0\) for \(k<0\). The moving average polynomial may have roots on the unit circle.

This is a simple illustration of the equations I give in my time series courses.

armaacf computes ARMA autocovariances. The default method computes computes the zero lag autocovariance using armaccf_xe() and multiplies the autocorrelations obtained from ARMAacf (which computes autocorrelations, not autocovariances). If compare = TRUE it also uses tacvfARMA from package ltsa and returns both results in a matrix for comparison. The matrix has columns "native", "tacvfARMA" and "difference", where the last column contains the (zapped) differences between the autocorrelations obtained by the two methods.

The ARMA parameters in argument model follow the Brockwell-Davis convention for the signs. Since tacvfARMA() uses the Box-Jenkins convention for the signs, the moving average parameters are negated for calls to tacvfARMA().

Value

for armaccf_xe, the crosscovariances for lags 0, ..., maxlag.

for armaacf, the autocovariances, see Details.

References

McLeod AI, Yu H, Krougly Z (2007). “Algorithms for Linear Time Series Analysis: With R Package.” Journal of Statistical Software, 23(5). doi:10.18637/jss.v023.i05 .

Author

Georgi N. Boshnakov

Note

armaacf is useful for exploratory computations but autocovariances is more convenient and eliminates the need to know function names for particular cases.

Examples

## Example 1 from ?ltsa::tacvfARMA
z <- sqrt(sunspot.year)
n <- length(z)
p <- 9
q <- 0
ML <- 5
out <- arima(z, order = c(p, 0, q))

phi <- theta <- numeric(0)
if (p > 0) phi <- coef(out)[1:p]
if (q > 0) theta <- coef(out)[(p+1):(p+q)]
zm <- coef(out)[p+q+1]
sigma2 <- out$sigma2

armaacf(list(ar = phi, ma = theta, sigma2 = sigma2), lag.max = 20)
#>          0          1          2          3          4          5          6 
#>  9.0416079  7.5475908  4.3845239  0.8271273 -1.9801678 -3.4909677 -3.3114507 
#>          7          8          9         10         11         12         13 
#> -1.5271174  1.2132068  4.1082578  6.0479060  6.3673284  4.9897294  2.5321902 
#>         14         15         16         17         18         19         20 
#> -0.1699738 -2.2803602 -3.1718781 -2.6404447 -0.9043874  1.4099559  3.5163219 
## this illustrates that the methods
## based on ARMAacf and tacvARMA are equivalent:
armaacf(list(ar = phi, ma = theta, sigma2 = sigma2), lag.max = 20, compare = TRUE)
#>        native  tacvfARMA difference
#> 0   9.0416079  9.0416079          0
#> 1   7.5475908  7.5475908          0
#> 2   4.3845239  4.3845239          0
#> 3   0.8271273  0.8271273          0
#> 4  -1.9801678 -1.9801678          0
#> 5  -3.4909677 -3.4909677          0
#> 6  -3.3114507 -3.3114507          0
#> 7  -1.5271174 -1.5271174          0
#> 8   1.2132068  1.2132068          0
#> 9   4.1082578  4.1082578          0
#> 10  6.0479060  6.0479060          0
#> 11  6.3673284  6.3673284          0
#> 12  4.9897294  4.9897294          0
#> 13  2.5321902  2.5321902          0
#> 14 -0.1699738 -0.1699738          0
#> 15 -2.2803602 -2.2803602          0
#> 16 -3.1718781 -3.1718781          0
#> 17 -2.6404447 -2.6404447          0
#> 18 -0.9043874 -0.9043874          0
#> 19  1.4099559  1.4099559          0
#> 20  3.5163219  3.5163219          0

## In the original example in ?ltsa::tacvfARMA
## the comparison is with var(z), not with the theoretical variance:
rA <- ltsa::tacvfARMA(phi, - theta, maxLag=n+ML-1, sigma2=sigma2)
rB <- var(z) * ARMAacf(ar=phi, ma=theta, lag.max=n+ML-1)
## so rA and rB are different.
## but the difference is due to the variance:
rB2 <- rA[1] * ARMAacf(ar=phi, ma=theta, lag.max=n+ML-1)
cbind(rA[1:5], rB[1:5], rB2[1:5])
#>         [,1]       [,2]       [,3]
#> 0  9.0416079  8.4034699  9.0416079
#> 1  7.5475908  7.0148975  7.5475908
#> 2  4.3845239  4.0750733  4.3845239
#> 3  0.8271273  0.7687504  0.8271273
#> 4 -1.9801678 -1.8404116 -1.9801678

## There is no need to use specific functions,
## autocovariances() is most convenient for routine use:
armalist <- list(ar = phi, ma = theta, sigma2 = sigma2)
autocovariances(armalist, maxlag = 10)
#> An object of class "Autocovariances"
#>      Lag_0      Lag_1      Lag_2      Lag_3      Lag_4      Lag_5      Lag_6 
#>  9.0416079  7.5475908  4.3845239  0.8271273 -1.9801678 -3.4909677 -3.3114507 
#>      Lag_7      Lag_8      Lag_9     Lag_10 
#> -1.5271174  1.2132068  4.1082578  6.0479060 

## even better, set up an ARMA model:
mo <- new("ArmaModel", ar = phi, ma = theta, sigma2 = sigma2)
autocovariances(mo, maxlag = 10)
#> An object of class "Autocovariances"
#>      Lag_0      Lag_1      Lag_2      Lag_3      Lag_4      Lag_5      Lag_6 
#>  9.0416079  7.5475908  4.3845239  0.8271273 -1.9801678 -3.4909677 -3.3114507 
#>      Lag_7      Lag_8      Lag_9     Lag_10 
#> -1.5271174  1.2132068  4.1082578  6.0479060