For this exercise, I selected the Data set “”Monthly riverflow in cms, Madison River near West Yellowstone, MT., 1923 1960“. This data set came from the Time Series Data Library created by Rob Hyndman.
The seasonal timing of snow, snowmelt, major rainfall, and dry periods determines the seasonal pattern of streamflow. These anticipated changes in streamflow throughout the year are called seasonal variability.
We plot the time series and apply classical additive and multiplicative, as well as advanced techniques for decomposition.
ys_flow<- tsdl[[300]]
#str(ys_flow)
autoplot(ys_flow, main="Madison River: Monthly Riverflow", ylab="Flow in cms", xlab="Month" )
#Classical
ys_flow %>% decompose() %>%
autoplot() + xlab("Year") + ggtitle("Additive Decomposition of Madison River Flow")
ys_flow %>% decompose(type = "multiplicative") %>%
autoplot() + xlab("Year") + ggtitle("Multiplicative Decomposition of Madison River Flow")
Multiplicative decomposition did not change the trend or data component much, but there is clearly more “leakage” in the remainder component with multiplicative decomposition, probably from the seasonal component.
In order to determine if these results can be used for forcasting, lets use more advanced techniques of decomposition: X11 and STL.
#X11
ys_flow %>% seas(x11 = "") -> fit
autoplot(fit) + ggtitle("X11 Decomposition of Madison River Flow")
ys_flow %>% stl(t.window = 13, s.window = "periodic", robust = TRUE) %>% autoplot() + ggtitle("STL Decomposition of Madison River Flow")
The X11 and STL method greatly reduces the remainder, showing a much clearer picture of the trend and the variation in seasonal component over time.
Below is the naive forecast of the seasonally adjusted flow data:
fit <- stl(ys_flow, t.window=13, s.window="periodic",
robust=TRUE)
fit %>% seasadj() %>% naive() %>%
autoplot() + ylab("Flow Index") +
ggtitle("River Flow: Naive forecasts of Seasonally Adjusted Data")
Next, the forecast is “reseasonalized” by adding in the seasoanl naive forecast of the seasonal data:
fit %>% forecast(method="naive") %>%
autoplot() + ylab("Flow Index")