diff --git a/5-regression.pdf b/5-regression.pdf index 91a922c..a1db3a2 100644 Binary files a/5-regression.pdf and b/5-regression.pdf differ diff --git a/7-exponentialsmoothing.Rmd b/7-exponentialsmoothing.Rmd index b88474a..8615367 100644 --- a/7-exponentialsmoothing.Rmd +++ b/7-exponentialsmoothing.Rmd @@ -59,7 +59,6 @@ $y_{T-5}$ & $(0.2)(0.8)^5$ & $(0.4)(0.6)^5$ & $(0.6)(0.4)^5$ & $(0.8)(0.2 \bottomrule \end{tabular} - ## Simple Exponential Smoothing \fontsize{14}{16}\sf @@ -87,7 +86,6 @@ $$ $$ * Unlike regression there is no closed form solution --- use numerical optimization. - ## Example: Oil production \fontsize{10}{11}\sf @@ -153,7 +151,6 @@ autoplot(fc) + ylab("Oil (millions of tonnes)") + xlab("Year") ``` - # Trend methods ## Holt's linear trend @@ -168,7 +165,7 @@ autoplot(fc) + \pause\vspace*{-0.2cm} * Two smoothing parameters $\alpha$ and $\beta^*$ ($0\le\alpha,\beta^*\le1$). - * $\ell_t$ level: weighted average between $y_t$ one-step ahead forecast for time $t$, $(\ell_{t-1} + b_{t-1}=\pred{y}{t}{t-1})$ + * $\ell_t$ level: weighted average between $y_t$ and one-step ahead forecast for time $t$, $(\ell_{t-1} + b_{t-1}=\pred{y}{t}{t-1})$ * $b_t$ slope: weighted average of $(\ell_{t} - \ell_{t-1})$ and $b_{t-1}$, current and previous estimate of slope. * Choose $\alpha, \beta^*, \ell_0, b_0$ to minimise SSE. @@ -294,13 +291,11 @@ s_{t} &= \gamma (y_{t}-\ell_{t-1}-b_{t-1}) + (1-\gamma)s_{t-m}, \end{align*} \end{block}\fontsize{12}{14}\sf - * $k=$ integer part of $(h-1)/m$. Ensures estimates from the final year are used for forecasting. * Parameters:  $0\le \alpha\le 1$,  $0\le \beta^*\le 1$,  $0\le \gamma\le 1-\alpha$  and $m=$ period of seasonality (e.g. $m=4$ for quarterly data). ## Holt-Winters additive method - * Seasonal component is usually expressed as $s_{t} = \gamma^* (y_{t}-\ell_{t})+ (1-\gamma^*)s_{t-m}.$ * Substitute in for $\ell_t$: @@ -308,9 +303,7 @@ s_{t} &= \gamma (y_{t}-\ell_{t-1}-b_{t-1}) + (1-\gamma)s_{t-m}, * We set $\gamma=\gamma^*(1-\alpha)$. * The usual parameter restriction is $0\le\gamma^*\le1$, which translates to $0\le\gamma\le(1-\alpha)$. - - -## Holt-Winters multiplicative +## Holt-Winters multiplicative method \fontsize{13}{14}\sf For when seasonal variations are changing proportional to the level of the series. @@ -373,7 +366,6 @@ s_{t} &= \gamma \frac{y_{t}}{(\ell_{t-1} + \phi b_{t-1})} + (1 - \gamma)s_{t-m} \end{align*} \end{block} - ## Your turn Apply Holt-Winters’ multiplicative method to the `gas` data. @@ -382,7 +374,6 @@ Apply Holt-Winters’ multiplicative method to the `gas` data. 1. Experiment with making the trend damped. 1. Check that the residuals from the best method look like white noise. - # Taxonomy of exponential smoothing methods ## Exponential smoothing methods @@ -419,9 +410,8 @@ There are also multiplicative trend methods (not recommended). \placefig{0}{1.4}{width=12.8cm}{pegelstable.pdf} - ## R functions -\fontsize{11.5}{15}\sf +\fontsize{11.5}{13}\sf * Simple exponential smoothing: no trend. \newline `ses(y)` @@ -437,8 +427,6 @@ There are also multiplicative trend methods (not recommended). * Combination of no trend with seasonality not possible using these functions. - - # Innovations state space models ## Methods v Models @@ -464,7 +452,6 @@ There are also multiplicative trend methods (not recommended). * Trend $=\{$N,A,A\damped$\}$ * Seasonal $=\{$N,A,M$\}$. - ## Exponential smoothing methods \fontsize{12}{14}\sf @@ -521,7 +508,6 @@ M,A,M: &Multiplicative Holt-Winters' method with multiplicative errors \pause \color{orange}{\bf There are 18 separate models in the ETS framework} - ## A model for SES \begin{block}{Component form}\vspace*{-0.4cm} @@ -569,14 +555,11 @@ Holt's linear method with additive errors. \end{align*} * For simplicity, set $\beta=\alpha \beta^*$. - ## Your turn \large * Write down the model for ETS(A,Ad,N) - - ## ETS(A,A,A) Holt-Winters additive method with additive errors. @@ -594,14 +577,11 @@ Holt-Winters additive method with additive errors. * Forecast errors: $\varepsilon_{t} = y_t - \hat{y}_{t|t-1}$ * $k$ is integer part of $(h-1)/m$. - ## Your turn \large - * Write down the model for ETS(A,N,A) - ## ETS(M,N,N) SES with multiplicative errors. @@ -639,12 +619,10 @@ Holt's linear method with multiplicative errors. \placefig{0}{1.5}{width=12.8cm,trim=0 120 0 0,clip=true}{fig_7_ets_add.pdf} - ## Multiplicative error models \placefig{0}{1.5}{width=12.8cm,trim=0 120 0 0,clip=true}{fig_7_ets_multi.pdf} - ## Estimating ETS models * Smoothing parameters $\alpha$, $\beta$, $\gamma$ and $\phi$, and the initial states $\ell_0$, $b_0$, $s_0,s_{-1},\dots,s_{-m+1}$ are estimated by maximising the "likelihood" = the probability of the data arising from the specified model. @@ -668,7 +646,6 @@ g(\bm{x}_{t-1})\varepsilon_t$\\ \end{tabular} \end{block} - Additive errors : \mbox{}\vspace*{-0.5cm}\newline $k(x)=1$.\qquad $y_t = \mu_{t} + \varepsilon_t$. @@ -731,7 +708,6 @@ which is the AIC corrected (for small sample bias). \] \end{block} - ## Automatic forecasting **From Hyndman et al.\ (IJF, 2002):** @@ -745,14 +721,12 @@ criterion). Method performed very well in M3 competition. - ## Some unstable models * Some of the combinations of (Error, Trend, Seasonal) can lead to numerical difficulties; see equations with division by a state. * These are: ETS(A,N,M), ETS(A,A,M), ETS(A,A\damped,M). * Models with multiplicative errors are useful for strictly positive data, but are not numerically stable with data containing zeros or negative values. In that case only the six fully additive models will be applied. - ## Exponential smoothing models \fontsize{11}{12}\sf @@ -832,7 +806,6 @@ $$\hat\varepsilon_t = y_t - \hat{y}_{t|t-1}$$ Multiplicative error model: $$\hat\varepsilon_t = \frac{y_t - \hat{y}_{t|t-1}}{\hat{y}_{t|t-1}}$$ - ## Forecasting with ETS models \structure{Point forecasts:} iterate the equations for $t=T+1,T+2,\dots,T+h$ and set all $\varepsilon_t=0$ for $t>T$.\pause @@ -840,7 +813,6 @@ $$\hat\varepsilon_t = \frac{y_t - \hat{y}_{t|t-1}}{\hat{y}_{t|t-1}}$$ * Not the same as $\text{E}(y_{t+h} | \bm{x}_t)$ unless trend and seasonality are both additive. * Point forecasts for ETS(A,x,y) are identical to ETS(M,x,y) if the parameters are the same. - ## Example: ETS(A,A,N) \vspace*{-1.3cm} @@ -913,7 +885,6 @@ PI for most ETS models: $\hat{y}_{T+h|T} \pm c \sigma_h$, where $c$ depends on c ets(h02) ``` - ## Example: drug sales \fontsize{8}{8}\sf @@ -921,7 +892,6 @@ ets(h02) ets(h02, model="AAA", damped=FALSE) ``` - ## The `ets()` function * Automatically chooses a model by default using the AIC, AICc or BIC. @@ -934,7 +904,6 @@ ets(h02, model="AAA", damped=FALSE) * **Methods:** `coef()`, `autoplot()`, `plot()`, `summary()`, `residuals()`, `fitted()`, `simulate()` and `forecast()` * `autoplot()` shows time plots of the original time series along with the extracted components (level, growth and seasonal). - ## Example: drug sales ```{r, echo=TRUE, fig.height=4} h02 %>% ets() %>% autoplot() @@ -946,9 +915,8 @@ h02 %>% ets() %>% autoplot() h02 %>% ets() %>% forecast() %>% autoplot() ``` - ## Example: drug sales -\fontsize{9}{12}\sf +\fontsize{11}{13}\sf ```{r, echo=TRUE} h02 %>% ets() %>% accuracy() @@ -973,7 +941,6 @@ accuracy(forecast(fit1,10), test) ## The `ets()` function in R \fontsize{12}{13}\sf - ```r ets(y, model = "ZZZ", damped = NULL, additive.only = FALSE, @@ -998,7 +965,6 @@ ets(y, model = "ZZZ", damped = NULL, * `damped=FALSE`, then a non-damped trend will used. * If `damped=NULL` (default), then either a damped or a non-damped trend will be selected according to the information criterion chosen. - ## The `ets()` function in R \fontsize{13}{14.5}\sf\vspace*{-0.2cm} @@ -1054,7 +1020,6 @@ ets(y, model = "ZZZ", damped = NULL, * `lambda`: The Box-Cox transformation parameter. Ignored if `lambda=NULL`. Otherwise, forecasts are back-transformed via inverse Box-Cox transformation. * `biasadj`: Apply bias adjustment after Box-Cox? - ## Your turn * Use `ets()` on some of these series:\vspace*{0.2cm}