This data is from the Federal Reserve Bank of St. Louis. It is the Consumer Price Index for All Urban Consumers: Electricity in U.S. City Average (not seasonally adjusted). Data is from 1/1970 to 5/2020. The data is indexed to 1982:1984 = 100.
Setup
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(ggplot2)
Setup
elecTS = ts(electricityData, frequency = 12, start = c(1970,1))
elecTS = elecTS[,-1]
autoplot(elecTS, ylab = "Electricity Price per kWh (US City Avg)", main = "US City Electricity Prices")
Additive decomposition
decompA = decompose(elecTS, type = "additive")
plot(decompA)
Multiplicative decomposition
decompM = decompose(elecTS, type = "multiplicative")
plot(decompM)
For this data, additive decomposition works better because the seasonal variation is consistent over the course of the time series.
Forecasting
fcast1 <- stlf(elecTS, method='rwdrift', h = 36)
autoplot(fcast1)
fcast2 <- stlf(elecTS, method='naive', h = 36)
autoplot(fcast2)
print('rwdrift')
## [1] "rwdrift"
accuracy(fcast1)
## ME RMSE MAE MPE MAPE MASE
## Training set 1.217415e-15 0.9698218 0.6648801 0.003477496 0.5549161 0.1529097
## ACF1
## Training set 0.02514197
print("naive")
## [1] "naive"
accuracy(fcast2)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.300798 1.015398 0.7033831 0.3140255 0.6009235 0.1617646
## ACF1
## Training set 0.02514197
The forecast here uses the stlf method to forecast seasonally adjusted data and then reseasonalize, as is shown in the textbook. It looks like rwdrift is a better method to use than naive in this case, although they are pretty similar.