Skip to contents

Convert between vector and season-lag representations of autocovariances of multivariate and periodically correlated time series.

Usage

sl2acfbase(mat, maxlag, fullblocks = FALSE)

acfbase2sl(acf)

sl2vecacf(mat, maxlag, fullblocks = FALSE)

Arguments

acf

an acf as returned by base R acf.

mat

a matrix containing autocovariances in season-lag arrangement.

maxlag

maximal lag, a positive integer.

fullblocks

if TRUE, keep full blocks only.

Details

These functions rearrange autocovariances and autocorrelations between the native season-lag arrangement in package ``pcts'' and the vector representations of the corresponding mutivariate models (vector of seasons representation of periodic models). Variable \(s\) is taken be season \(s\) and vice versa in the opposite direction.

``acfbase'' in the names of the functions refers to the representation returned by base function acf.

acfbase2sl rearranges a multivariate acf in season-lag form.

sl2acfbase rearranges a season-lag form into the multivariate form used by base function acf.

sl2vecacf is similar to sl2acfbase but the result is such that the lag is in the third dimension and r[ , , k] is \(Cov(X_{t}, X_{t-k})\) (not its transpose). See also the examples below and in acf2Lagged.

Value

for acfbase2sl, a matrix. for sl2acfbase and sl2vecacf, an array.

Author

Georgi N. Boshnakov

Examples

## use a character matrix to illustrate the positions of the elements
matsl <- rbind(paste0("Ra", 0:3), paste0("Rb", 0:3))
matsl
#>      [,1]  [,2]  [,3]  [,4] 
#> [1,] "Ra0" "Ra1" "Ra2" "Ra3"
#> [2,] "Rb0" "Rb1" "Rb2" "Rb3"
## convert to what I consider "standard" vec format R(k)=EX_tX_{t-k}'
sl2vecacf(matsl)
#> , , 1
#> 
#>      [,1]  [,2] 
#> [1,] "Ra0" "Rb1"
#> [2,] "Rb1" "Rb0"
#> 
#> , , 2
#> 
#>      [,1]  [,2] 
#> [1,] "Ra2" "Ra1"
#> [2,] "Rb3" "Rb2"
#> 
#> , , 3
#> 
#>      [,1] [,2] 
#> [1,] NA   "Ra3"
#> [2,] NA   NA   
#> 
## convert to the format from acf() (R(k) is the transposed from mine).
sl2acfbase(matsl)
#> , , 1
#> 
#>      [,1]  [,2] 
#> [1,] "Ra0" "Rb1"
#> [2,] "Ra2" "Ra1"
#> [3,] NA    "Ra3"
#> 
#> , , 2
#> 
#>      [,1]  [,2] 
#> [1,] "Rb1" "Rb0"
#> [2,] "Rb3" "Rb2"
#> [3,] NA    NA   
#> 
identical(sl2vecacf(matsl), aperm(sl2acfbase(matsl), c(3, 2, 1))) # TRUE
#> [1] TRUE

## by default the conversion is lossles;
## so this contains all values from the original and some NA's:
sl2acfbase(matsl)
#> , , 1
#> 
#>      [,1]  [,2] 
#> [1,] "Ra0" "Rb1"
#> [2,] "Ra2" "Ra1"
#> [3,] NA    "Ra3"
#> 
#> , , 2
#> 
#>      [,1]  [,2] 
#> [1,] "Rb1" "Rb0"
#> [2,] "Rb3" "Rb2"
#> [3,] NA    NA   
#> 
## the orignal, matsl, can be restored:
acfbase2sl(sl2acfbase(matsl))
#>      [,1]  [,2]  [,3]  [,4] 
#> [1,] "Ra0" "Ra1" "Ra2" "Ra3"
#> [2,] "Rb0" "Rb1" "Rb2" "Rb3"
identical(acfbase2sl(sl2acfbase(matsl)), matsl)  # TRUE
#> [1] TRUE

## this drops some values (if necessary) to keep complete block only
sl2acfbase(matsl, fullblocks = TRUE)
#> , , 1
#> 
#>      [,1]  [,2] 
#> [1,] "Ra0" "Rb1"
#> [2,] "Ra2" "Ra1"
#> 
#> , , 2
#> 
#>      [,1]  [,2] 
#> [1,] "Rb1" "Rb0"
#> [2,] "Rb3" "Rb2"
#>