-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathForecasting-4-2-Exp-Smoothing.Rmd
54 lines (35 loc) · 1.22 KB
/
Forecasting-4-2-Exp-Smoothing.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## `ets()` function
The `ets()` function in the **forecast** package fits exponential smoothing models and produces forecasts from the fitted models. It also includes functions for plotting forecasts.
Load the data by loading the **FishForecast** package.
```{r load_data_exp_smoothing}
require(FishForecast)
```
Fit the model.
```{r fit.ann}
fit <- forecast::ets(anchovy87ts, model="ANN")
```
`model="ANN"` specifies the simple exponential smoothing model.
Create a forecast for 5 time steps into the future.
```{r fr.ann}
fr <- forecast::forecast(fit, h=5)
```
Plot the forecast.
```{r}
plot(fr)
```
Look at the estimates
```{r}
fit
```
### The weighting function
The first coefficient of the ets fit is the $\alpha$ parameter for the weighting function.
```{r ann.weighting, fig.cap="Weighting function for the simple exponential smoothing model for anchovy."}
alpha <- coef(fit)[1]
wts <- alpha*(1-alpha)^(0:23)
plot(1987:1964, wts/sum(wts), lwd=2, ylab="weight", xlab="", type="l")
```
### Decomposing your model fit
Sometimes you would like to see the smoothed level that the model estimated. You can see that with `plot(fit)` or `autoplot(fit)`.
```{r fig.height=4, fig.cap="Decompositon of an ets fit."}
autoplot(fit)
```