TBATS

Time Series

TBATS for Time Series Data

Yeongeun Jeon , Jung In Seo
09-07-2021

Introduction



Application


Data 불러오기

pacman::p_load("dplyr", "forecast", "parallel")

# In Mac
# guess_encoding("Amtrak.csv")
# Amtrak.data <- read.csv("Amtrak.csv", fileEncoding="EUC-KR")

Amtrak.data  <- read.csv("C:/Users/User/Desktop/Amtrak.csv")
ridership.ts <- ts(Amtrak.data$Ridership, start=c(1991,1), end=c(2004,3), freq=12)

Data 분할

train.ts  <- window(ridership.ts,start=c(1991,1), end=c(2001,3))   # Training Data
test.ts   <- window(ridership.ts,start=c(2001,4))                  # Test Data
n.test    <- length(test.ts)

모형 적합

tbats(
  y,
  use.box.cox = NULL,
  use.trend = NULL,
  use.damped.trend = NULL,
  seasonal.periods = NULL,
  use.arma.errors = TRUE,
  use.parallel = length(y) > 1000,
  num.cores = 2,
  bc.lower = 0,
  bc.upper = 1,
  biasadj = FALSE,
  model = NULL,
  ...
)

cl <- parallel::makeCluster(detectCores(), setup_timeout = 0.5)
TBATS.fit <- train.ts %>%
  tbats(use.box.cox = FALSE,
        use.trend = TRUE,
        use.damped.trend = TRUE,
        use.parallel = TRUE,
        num.cores = cl)

summary(TBATS.fit)
                  Length Class  Mode     
lambda               0   -none- NULL     
alpha                1   -none- numeric  
beta                 1   -none- numeric  
damping.parameter    1   -none- numeric  
gamma.one.values     1   -none- numeric  
gamma.two.values     1   -none- numeric  
ar.coefficients      0   -none- NULL     
ma.coefficients      0   -none- NULL     
likelihood           1   -none- numeric  
optim.return.code    1   -none- numeric  
variance             1   -none- numeric  
AIC                  1   -none- numeric  
parameters           2   -none- list     
seed.states         12   -none- numeric  
fitted.values      123   ts     numeric  
errors             123   ts     numeric  
x                 1476   -none- numeric  
seasonal.periods     1   -none- numeric  
k.vector             1   -none- numeric  
y                  123   ts     numeric  
p                    1   -none- numeric  
q                    1   -none- numeric  
call                 7   -none- call     
series               1   -none- character
method               1   -none- character

예측

TBATS.forecast <- forecast(TBATS.fit, h=n.test)
TBATS.forecast$mean
          Jan      Feb      Mar      Apr      May      Jun      Jul
2001                            1978.995 2028.484 1959.201 2089.790
2002 1721.923 1658.583 1979.689 1966.634 2018.589 1951.281 2083.449
2003 1720.255 1657.248 1978.620 1965.779 2017.904 1950.732 2083.010
2004 1720.140 1657.155 1978.546                                    
          Aug      Sep      Oct      Nov      Dec
2001 2116.995 1814.845 1914.140 1924.798 1938.481
2002 2111.919 1810.782 1910.888 1922.195 1936.397
2003 2111.568 1810.501 1910.663 1922.015 1936.252
2004                                             
plot(TBATS.forecast)
accuracy(c(TBATS.forecast$mean), test.ts)
               ME    RMSE      MAE      MPE    MAPE     ACF1
Test set 69.36452 103.114 88.31896 3.379683 4.42057 0.556916
         Theil's U
Test set 0.5999032

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".