Thursday, June 27, 2013

Exponential Smoothing Model

Exponential Smoothing Model

Exponential Smoothing Model

Proud Economy 0005

I'm looking at “Forecasting With Exponential Smoothing: The State Space Approach” by Hyndman etal. (2008) and “Forecasting: principles and practice” by Hyndman and Athanasopoulos (2013). Hyndman is the maintainer of the R forecast package. Lots of cool stuff to learn here.

I discovered them while researching the exponential smoothingets” function.

library(forecast)
library(Quandl)
# Quandl.auth('yourauthenticationtoken')
getts <- function(series) {
    y <- Quandl(series, collapse = "quarterly", type = "xts")
    layout(matrix(c(1, 1, 2, 3), 2, 2, byrow = TRUE))
    plot.ts(y, main = series, ylab = series)
    acf(y, main = "Autocorrelations", ylim = c(-1, 1))
    pacf(y, main = "Partial Autocorrelations", ylim = c(-1, 1))
    return(y)
}

data:

“Gross domestic product (GDP), the featured measure of U.S. output, is the market value of the goods and services produced by labor and property located in the United States.”

gdp <- getts("FRED/GDPC1")

plot of chunk unnamed-chunk-4

We'll take all the defaults to see what happens automatically with the “ets” function and follow it with default “forecast”.

gdp_ets <- ets(gdp)
summary(gdp_ets)
## ETS(A,Ad,N) 
## 
## Call:
##  ets(y = gdp) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
##     beta  = 0.4832 
##     phi   = 0.8936 
## 
##   Initial states:
##     l = 1756.5772 
##     b = 13.5391 
## 
##   sigma:  53.14
## 
##  AIC AICc  BIC 
## 3594 3594 3612 
## 
## Training set error measures:
##                 ME  RMSE   MAE   MPE  MAPE   MASE     ACF1
## Training set 9.143 53.14 39.25 16.14 71.64 0.6679 -0.02005
gdp_fit <- forecast(gdp_ets)
summary(gdp_fit)
## 
## Forecast method: ETS(A,Ad,N)
## 
## Model Information:
## ETS(A,Ad,N) 
## 
## Call:
##  ets(y = gdp) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
##     beta  = 0.4832 
##     phi   = 0.8936 
## 
##   Initial states:
##     l = 1756.5772 
##     b = 13.5391 
## 
##   sigma:  53.14
## 
##  AIC AICc  BIC 
## 3594 3594 3612 
## 
## Error measures:
##                 ME  RMSE   MAE   MPE  MAPE   MASE     ACF1
## Training set 9.143 53.14 39.25 16.14 71.64 0.6679 -0.02005
## 
## Forecasts:
##     Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 266          13774 13706 13842 13670 13878
## 267          13817 13669 13964 13592 14042
## 268          13855 13640 14070 13526 14184
## 269          13889 13609 14170 13460 14318
## 270          13920 13575 14265 13392 14448
## 271          13947 13538 14356 13321 14573
## 272          13971 13499 14444 13248 14694
## 273          13993 13458 14529 13174 14812
## 274          14013 13415 14610 13099 14927
## 275          14030 13372 14689 13023 15038
plot(gdp_fit)

plot of chunk unnamed-chunk-5

Here's another blog article on “Learning Time Series with R” by Joseph Rickert that I just discovered. He lists several of the books that I've been looking at. I'm having fun exploring this stuff so far.

Gary Young

2 comments:

  1. You seem to be trying random things, but you know some of the statistical vocabulary. If this blog is about what a "normal person" could do, could you include a little more about how you choose what to try? (Even if it is as simple as walking down a Wikipedia page about statistics and trying each thing in turn.)

    Also, a normal person isn't going to follow your links until they start understanding what's going on enough to really get interested. I don't have any specific feedback to offer, just an observation of your audience.

    Overall, this seems really cool! I'm glad you're blogging from the very beginning of the experiment. That will be highly useful later as you start having polished models and someone wants to see how you got there.

    ReplyDelete
  2. Initially I am trying random things. I'm logging everything that I do and linking to all the sources, to show what I've found that anyone can use. Since I'm in the learning process, I'll add everything that I figure out as I go. I'll especially point to sources that I use to figure things out. When I go to wikipedia, I'm usually lost as the articles are mostly written for people that are at the authors level. Every thing else on the Internet initially has no structure until I identify the sites that point the way to go. I'm doing what I can and I invite all the help that I can get.

    Gary

    ReplyDelete