Input Data Formats Used by SSA Routines
The inputs of SSA can be quite different depending on the kind of SSA used. However, there is a common of all the variants of SSA and all the routines. The package tries hard to preserve the specifics of input object as much as possible. This means, that all the attributes, etc. are copied back to the reconstructed objects. This way, the result of the SSA decomposition of a 'ts' object is a 'ts' object as well.
For forecasting, it is not possible in general to preserve the
attributes of the input objects. However,
Rssa knows about some
common time series classes (e.g. 'ts') and tries to infer the time
scales for forecasted objects as well.
The input formats are as follows:
1d SSA and Toeplitz SSA
Input is assumed to be a simple vector, or vector-like object (e.g. univariare 'ts' or 'zooreg' object). Everything else is coerced to vector.
Input assumed to be a matrix. If there are any
NA's then the
shaped variant of 2d SSA will be used. All non-
will be used as a mask.
Input assumed to be an array of arbitrary dimension. If there are any
NA's then the shaped variant will be used.
While the representation of a one dimensional time series in R is pretty obvious, there are multiple possible ways of defining the multivariate time series. Let us outline some common choices.
Matrix with separate series in the columns. Optionally, additional time structure like in 'mts' objects, can be embedded.
Matrix-like (e.g. a 'data.frame') object with series in the columns. In particular, 'data.frame' would be a result of reading the series from the file via 'read.table' function.
List of separate time series objects (e.g. a 'list' of 'ts' or 'zoo' objects).
Also, the time scales of the individual time series can be
normalized via head or tail padding with
NA (for example, as
a result of the
ts.union call), or specified via time series
attributes. Or, everything can be mixed all together.
ssa routine with 'kind = mssa' allows one to provide any
of the outlined multivariate series formats. As usual, all the
attributes, names of the series, NA padding, etc. is carefully
Complex vectors are assumed at the input.
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
s <- ssa(co2) # Perform the decomposition using the default window length r <- reconstruct(s, groups = list(Trend = c(1, 4), Seasonality = c(2, 3))) # Reconstruct into 2 series class(r$Trend) # Result is 'ts' object # Simultaneous trend extraction using MSSA s <- ssa(EuStockMarkets, kind = "mssa") r <- reconstruct(s, groups = list(Trend = c(1,2))) class(r$Trend) # Result is 'mts' object # Trend forecast f <- rforecast(s, groups = list(Trend = c(1, 2)), len = 50, only.new = FALSE) class(f) # For 'ts' objects the time scales are inferred automatically # Artificial image for 2dSSA mx <- outer(1:50, 1:50, function(i, j) sin(2*pi * i/17) * cos(2*pi * j/7) + exp(i/25 - j/20)) + rnorm(50^2, sd = 0.1) # Decompose 'mx' with circular window s <- ssa(mx, kind = "2d-ssa", wmask = circle(5), neig = 10) # Reconstruct r <- reconstruct(s, groups = list(1, 2:5)) # Plot components, original image and residuals plot(r) # 3D-SSA example (2D-MSSA) data(Barbara) ss <- ssa(Barbara, L = c(50, 50, 1)) plot(ss)