0
votes

I want to understand how forecast from STL function in R works. So, I am not giving any reproducible code here.

Below is the procedure that I worked on time series

  1. I used STL decomposition on my time series.
  2. Checked residuals component from step 1 for white noise using Box.test
  3. Found that residuals are not white-noise. So, used ARIMA model to fit a forecasting model.

Now, my task is to compute forecast values that consist of a. Seasonal and Trend component from step 1 above b. Residuals component from ARIMA model - from step 3 above.

If I use

forecast(stl(..)), 

it gives me

 Point Forecast     Lo 80    Hi 80    Lo 95    Hi 95 

However, I am interested in only seasonal and trend parts of forecast. How can I get seasonal trend components?

What components does constitute forecast(stl(..))

Please advise.

1
As far as I am concerned your second sentence doomed this question for SO. Requests for statistical tutorials are off-topic on SO. - IRTFM
@Chandra If the below answer solves your problem then please accept it as answer so that others can also use it. Thanks! - Jasmeet
@freetiger, Thank you for replying. I will work on this problem again and confirm. Please give me some time. - Chandra

1 Answers

0
votes

I am not sure if you want to use forecast with STL or not, but if you just want to extract seasonal and trend component from STL then code below may work fine for you.

## Let's build a monthly time series first

dat_monthly <- cumsum(rnorm(39,0,5))
x_monthly <- ts(dat_monthly, frequency = 12, start = c(2013,1))
stl(x_monthly, "periodic")

stl(x_monthly, s.window = "periodic")$time.series[, "seasonal"] ## for seasonal part
stl(x_monthly, s.window = "periodic")$time.series[, "trend"] ## for trend part