Skip to contents

Core data of periodic time series.

Usage

Vec(x, ...)

tsMatrix(x, ...)

tsVector(x, ...)

tsVec(x, ...)

pcMatrix(x, ...)

pcArray(x, ndim = 3, ...)

pctsArray(x, ndim = 3, ...)

Arguments

x

an object.

...

further arguments for methods.

ndim

currently not used.

Details

These functions give the core data in various common forms.

The data values can be extracted as a vector from a periodic time series object, say x, with as.vector(x) or as(x, "vector"). Similarly, as.matrix() and as(x, "matrix") extract the data as a matrix containing one column per variable. For multivariate time series the vector returned by as.vector(x) (or as(x, "vector")) is equivalent to as.vector(as.matrix(x)).

Vec() is like as.vector() but returns the result as a matrix with one column (column vector), as is usual in matrix calculus. The default does literally this.

The most common representation of data in statistics is matrix-like with one column per variable. The descriptions of algorithms for multivariate time series however usually define the vector of observations at a given time to be a column vector. In particular, implementations of the Kalman filter often require precisely this arrangement. In that case the data matrix is the transposed of the more common one and the vectorising operation stacks the observations, not the variables.

The functions tsMatrix(), tsVector() and tsVec() provide the analogues of as.vector(), as.matrix() and Vec() for the ``transposed'' arrangement.

These functions may look redundant since they are simple combinations of the above and traspose operations. Having functions makes for more readable programming. They may be more efficient, as well, for example if the underlying time series class stores the data in the transposed format.

pcMatrix() and pcArray() also give the core data. Effectively, they give an additional dimension to the seasons. The season becomes the first dimension since for column oriented data the season changes fastest. pcMatrix is most suitable for univariate time series, pcArray() for multivariate. Note that pcArray() easily extends to multiple periodicities although currently (2019-04-19) there are no methods that exploit this.

For univariate time series, in the matrix returned by pcMatrix() each row represents the data for one season and each column for one cycle. For multivariate time series, the matrices for each variable are put next to each other.

pcArray() returns the data as an array, whose last dimension corresponds to variables. In the default case the array is 3-dimensonal with dimensions (season, year, variable).

pctsArray() is a variant of pcArray() corresponding to the arrangement of tsMatrix(). The ordering of the dimensions here is (variable, season, cycle).

Value

vector, matrix or array, as indicated by the name of the function and described in Details.

Author

Georgi N. Boshnakov

Examples

## window to make number of years different from number of months
ap <- pcts(window(AirPassengers, start = c(1956, 1)))
class( as.vector(ap)    )
#> [1] "numeric"
class( as(ap, "vector") )
#> [1] "numeric"

dim( as.matrix(ap)    )
#> [1] 60  1
dim( as(ap, "matrix") )
#> [1] 60  1

dim( tsMatrix(ap) )
#> [1]  1 60

class( tsVector(ap) ) 
#> [1] "numeric"
dim(   tsVec(ap)    ) 
#> [1] 60  1

dim( pcMatrix(ap)   )
#> [1] 12  5
dim( pcArray(ap)    )
#> [1] 12  5  1
dim( pctsArray(ap)  )
#> [1]  1 12  5

dfr <- pcts(dataFranses1996)
dim(dfr)                     # c(148, 19)
#> [1] 148  19
nSeasons(dfr)                # 4
#> [1] 4

length(as.vector(dfr))
#> [1] 2812

all.equal(as.vector(dfr)[1:148],       as.matrix(dfr)[ , 1]) # TRUE
#> [1] TRUE
all.equal(tsVector(dfr)[1:19],  unname(as.matrix(dfr)[1, ])) # TRUE
#> [1] TRUE

dim( as.matrix(dfr) ) # c(148, 19)
#> [1] 148  19
dim( tsMatrix(dfr)  ) # c(19, 148)
#> [1]  19 148
all.equal(tsMatrix(dfr)[ , 1],  as.matrix(dfr)[1, ]) # TRUE
#> [1] TRUE

dim( Vec(dfr)   ) 
#> [1] 2812    1
dim( tsVec(dfr) ) 
#> [1] 2812    1
all.equal(tsVec(dfr)[1:19],  unname(as.matrix(dfr)[1, ])) # TRUE
#> [1] TRUE

dim( pcMatrix(dfr)   ) # c(4, 703), one row for each season
#> [1]   4 703
dim( pcArray(dfr)    ) # c(4, 37, 19), note: 703 == 37*19   
#> [1]  4 37 19

dim( pctsArray(dfr)  ) # c(19, 4, 37), note: 703 == 37*19   
#> [1] 19  4 37