Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post How to perform TBATS Model in R appeared first on Data Science Tutorials

What do you have to lose?. Check out Data Science tutorials here Data Science Tutorials.

How to perform TBATS Model in R?, The term “TBATS” refers to a well-liked time series forecasting technique and stands for

• Trigonometric seasonality
• Box-Cox transformation
• ARMA errors
• Trend
• Seasonal components.

How to compare the performance of different algorithms in R? (datasciencetut.com)

The following models can be used with and without this method

• Seasonality
• A Box-Cox transformation
• ARMA(p, q) process
• Various trends
• Various seasonal effects

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

## How to perform TBATS Model in R

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

Difference between R and Python – Data Science Tutorials

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

How to Fit a TBATS Model in R, for instance.

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

Dataset USAccDeaths:-

```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)
fit <- tbats(USAccDeaths)
predict <- predict(fit)
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 output includes the predicted death toll for the following months as well as the 80% and 95% confidence intervals.

How do confidence intervals work? – Data Science Tutorials

The forecasts for January 1979, for instance, are as follows:

8,307.597 fatalities are anticipated.

Death toll: [7982.943, 8632.251] 80% Confidence Interval ]

Death toll 95% Confidence Interval: [7811.081, 8804 .113]

These anticipated future values can also be plotted using the plot() function.

The Multinomial Distribution in R – Data Science Tutorials

`plot(forecast(fit))`

The post How to perform TBATS Model in R appeared first on Data Science Tutorials

Learn how to expert in the Data Science field with Data Science Tutorials.