Can I decompose a time series with multiple seasonalities (an msts
object) using tbats
(in the forecast
package for R) and get the random component of it? Just as getting the random component using the decompose
function for ts
objects?
Contents
hide
Best Answer
You can use the function tbats.components
on a tbats
model fit. It will yield a matrix of time series containing the level, the slope and the season of the fitted model, as well as the actual observations. You can then simply subtract the components from the observations to obtain the residuals:
> library(forecast) > fit <- tbats(USAccDeaths) > foo <- tbats.components(fit) > head(foo) observed level slope season [1,] 9007 9538.066 -43.81329 -823.6141 [2,] 8106 9590.489 -47.90006 -1548.1921 [3,] 8928 9642.926 -52.03042 -781.2602 [4,] 9137 9636.436 -52.12401 -528.4124 [5,] 10017 9661.657 -54.41414 304.7762 [6,] 10826 9848.610 -67.92587 815.5472 > foo[,"observed"]-foo[,"level"]-foo[,"slope"]-foo[,"season"] Jan Feb Mar Apr May 1973 336.3616979 111.6033706 118.3650491 81.1007939 104.9810786 1974 -222.9725629 -120.0746460 65.3314214 84.8823480 -199.9296274 1975 88.0935771 -12.2533927 20.1954758 -210.2334112 194.5652535 1976 91.6890807 225.6898321 -108.3721742 -104.6956780 -128.2708712 1977 18.9462879 -59.0440990 -48.6638245 9.8410292 -38.2662635 1978 -43.2497726 -132.1089133 -25.8376148 29.8293887 34.8255629 Jun Jul Aug Sep Oct 1973 229.7689357 9.7833829 97.6213834 114.7690243 61.5528845 1974 23.6012054 -100.8973484 99.0247537 33.6304182 37.2522537 1975 -59.5136479 -162.8834589 -5.6052057 -131.8664155 -149.6577923 1976 -168.0888948 16.7956107 -130.6105420 -127.4818202 -48.5429559 1977 -81.8158991 155.2481713 -232.3853212 -95.3328947 18.0666666 1978 -82.3539729 38.3254629 8.2383295 149.0925592 -93.5561732 Nov Dec 1973 -24.4337637 -201.9057433 1974 70.8572386 -105.5657300 1975 5.6164054 -211.3018369 1976 -94.9396877 127.1735861 1977 -34.9677557 65.1114921 1978 0.1845764 136.0468109