TBATS Time Series Modelling in R

[This article was first published on Data Analysis in R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post TBATS Time Series Modelling in R appeared first on finnstats.

TBATS Time Series Modelling in R, The term “TBATS” refers to a well-liked time series forecasting technique and stands for

  1. Trigonometric seasonality
  2. Box-Cox transformation
  3. ARMA errors
  4. Trend
  5. Seasonal components

The following models can be used with and without this method

  1. Seasonality
  2. A Box-Cox transformation
  3. ARMA(p, q) process
  4. Various trends
  5. Various seasonal effects

The final model in this procedure will be the one with the lowest Akaike Information Criterion (AIC) score.

Using the tbats function from the forecast package is the simplest way to fit a TBATS model to a time series dataset in R.

How to actually use this function is demonstrated in the example that follows.

How to Fit a TBATS Time Series Modelling in R

We’ll use USAccDeaths, a built-in R dataset that contains values for the total monthly accidental fatalities in the USA from 1973 to 1978, for this example.

Now we can view the USAccDeaths dataset

USAccDeaths
       Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
1973  9007  8106  8928  9137 10017 10826 11317 10744  9713  9938  9161  8927
1974  7750  6981  8038  8422  8714  9512 10120  9823  8743  9129  8710  8680
1975  8162  7306  8124  7870  9387  9556 10093  9620  8285  8466  8160  8034
1976  7717  7461  7767  7925  8623  8945 10078  9179  8037  8488  7874  8647
1977  7792  6957  7726  8106  8890  9299 10625  9302  8314  8850  8265  8796
1978  7836  6892  7791  8192  9115  9434 10484  9827  9110  9070  8633  9240

To fit a TBATS model to this dataset and forecast the values of upcoming months, use the following code.

library(forecast)

Yes, now we can fit the TBATS model

TBATSfit <- tbats(USAccDeaths)

Let’s use the model to make the predictions

predict <- predict(TBATSfit)

We can view the predictions     

predict
        Point Forecast     Lo 80     Hi 80    Lo 95     Hi 95
Jan 1979       8307.597  7982.943  8632.251 7811.081  8804.113
Feb 1979       7533.680  7165.539  7901.822 6970.656  8096.704
Mar 1979       8305.196  7882.740  8727.651 7659.106  8951.286
Apr 1979       8616.921  8150.753  9083.089 7903.978  9329.864
May 1979       9430.088  8924.028  9936.147 8656.137 10204.038
Jun 1979       9946.448  9403.364 10489.532 9115.873 10777.023
Jul 1979      10744.690 10167.936 11321.445 9862.621 11626.760
Aug 1979      10108.781  9499.282 10718.280 9176.632 11040.929
Sep 1979       9034.784  8395.710  9673.857 8057.405 10012.162
Oct 1979       9336.862  8668.087 10005.636 8314.060 10359.664
Nov 1979       8819.681  8124.604  9514.759 7756.652  9882.711
Dec 1979       9099.344  8376.864  9821.824 7994.407 10204.282
Jan 1980       8307.597  7563.245  9051.950 7169.208  9445.986
Feb 1980       7533.680  6769.358  8298.002 6364.750  8702.610
Mar 1980       8305.196  7513.281  9097.111 7094.067  9516.325
Apr 1980       8616.921  7800.849  9432.993 7368.847  9864.995
May 1980       9430.088  8590.590 10269.585 8146.187 10713.988
Jun 1980       9946.448  9084.125 10808.771 8627.639 11265.257
Jul 1980      10744.690  9860.776 11628.605 9392.859 12096.522
Aug 1980      10108.781  9203.160 11014.402 8723.753 11493.809
Sep 1980       9034.784  8109.000  9960.567 7618.920 10450.647
Oct 1980       9336.862  8390.331 10283.392 7889.269 10784.455
Nov 1980       8819.681  7854.387  9784.976 7343.391 10295.972
Dec 1980       9099.344  8114.135 10084.554 7592.597 10606.092

The predicted death toll for the following months is displayed along with the confidence ranges of 80% and 95%.

For instance, the forecasts are as follows for January 1979:

Deaths are expected to total 8,307.597.

[7,982.943, 8,632.251] is the 80 percent confidence interval for the number of fatalities ]

A 95 percent [7,811.081, 8,804.113] is the confidence interval for the number of deaths]

We can also plot these anticipated future values using the plot() function:

Now we can plot the predicted values

plot(forecast(TBATSfit))

Future anticipated values are represented by the blue line, while the confidence interval bounds are shown by the grey bands.

Naive Approach Forecasting Example »

If you are interested to learn more about data science, you can find more articles here finnstats.

The post TBATS Time Series Modelling in R appeared first on finnstats.

To leave a comment for the author, please follow the link and comment on their blog: Data Analysis in R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)