Github Link Web Link
Exponential Smoothing Forecasting Method
- Simple Exponential Smoothing
###
??global_economy ##Economic indicators featured by the World Bank from 1960 to 2017​
## starting httpd help server ... done
#Variables: GDP, Growth, CPI, Imports, Exports, Population​
# create data frame
algeria_economy <- global_economy %>%
filter(Country == "Algeria")#%>%
#mutate(GDP = round(GDP,5))%>%
#mutate(Exports_R = round(((GDP*Exports)/100), 5))%>%
#dplyr::select(Year, GDP, Exports)
algeria_economy %>%
autoplot(Exports) +
labs(y = "Exports in % of GDP", title = "Algeria Exports of goods and services relatively to GDP from 1960 to 2017")

# Estimate parameters
fit <- algeria_economy %>%
model(ETS(Exports ~ error("A") + trend("N") + season("N")))
fc <- fit %>%
forecast(h = 5)
fc %>%
autoplot(algeria_economy) +
geom_line(aes(y = .fitted), col="#D55E00",
data = augment(fit)) +
labs(y = "Exports in % of GDP", title = "Algeria Exports of goods and services relatively to GDP from 1960 to 2017") +
guides(colour = "none")

#alpha parameter
tidy(fit)
## # A tibble: 2 x 4
## Country .model term estimate
## <fct> <chr> <chr> <dbl>
## 1 Algeria "ETS(Exports ~ error(\"A\") + trend(\"N\") + season(\"~ alpha 0.840
## 2 Algeria "ETS(Exports ~ error(\"A\") + trend(\"N\") + season(\"~ l[0] 39.5
#Another way of calling simple exponential smoothing
algeria_eco <- ses(algeria_economy$Exports, alpha = .2, h = 5)
autoplot(algeria_eco)

algeria_eco$model #parameter
## Simple exponential smoothing
##
## Call:
## ses(y = algeria_economy$Exports, h = 5, alpha = 0.2)
##
## Smoothing parameters:
## alpha = 0.2
##
## Initial states:
## l = 30.3265
##
## sigma: 7.601
##
## AIC AICc BIC
## 472.7502 472.9684 476.8711
- Double Exponential Smoothing
#head(aus_livestock)
aus_economy <- global_economy %>%
filter(Code == "AUS") %>%
mutate(Pop = Population / 1e6)
autoplot(aus_economy, Pop) +
labs(y = "Population in Millions", title = "Australian Total Population from 1960 to 2017")

fit <- aus_economy %>%
model(
AAN = ETS(Pop ~ error("A") + trend("A") + season("N"))
)
fc <- fit %>%
forecast(h = 10)
aus_economy %>%
model(
`Holt's method` = ETS(Pop ~ error("A") +
trend("A") + season("N")),
#`Damped Holt's method` = ETS(Pop ~ error("A") +
# trend("Ad", phi = 0.9) + season("N"))
) %>%
forecast(h = 15) %>%
autoplot(aus_economy, level = NULL) + #geom_line(aes(y = .fitted), col="#D55E00",data = augment(fit))+
labs(y = "Population in Millions", title = "Australian Total Population from 1960 to 2017")

# + guides(fill = guide_legend(title = "Forecast", label.position = "left"))
tidy(fit)
## # A tibble: 4 x 4
## Country .model term estimate
## <fct> <chr> <chr> <dbl>
## 1 Australia AAN alpha 1.00
## 2 Australia AAN beta 0.327
## 3 Australia AAN l[0] 10.1
## 4 Australia AAN b[0] 0.222
- Triple Exponential Smoothing
#head(aus_livestock)
aus_holidays <- tourism %>%
filter(Purpose == "Holiday") %>%
summarise(Trips = sum(Trips)/1e3)
fit <- aus_holidays %>%
model(
additive = ETS(Trips ~ error("A") + trend("A") +
season("A")),
multiplicative = ETS(Trips ~ error("M") + trend("A") +
season("M"))
)
fc <- fit %>% forecast(h = "3 years")
fc %>%
autoplot(aus_holidays, level = NULL) +
labs(title="Australian domestic tourism",
y="Overnight trips (millions)") +
guides(colour = guide_legend(title = "Forecast"))

tidy(fit)
## # A tibble: 18 x 3
## .model term estimate
## <chr> <chr> <dbl>
## 1 additive alpha 0.262
## 2 additive beta 0.0431
## 3 additive gamma 0.000100
## 4 additive l[0] 9.79
## 5 additive b[0] 0.0211
## 6 additive s[0] -0.534
## 7 additive s[-1] -0.670
## 8 additive s[-2] -0.294
## 9 additive s[-3] 1.50
## 10 multiplicative alpha 0.224
## 11 multiplicative beta 0.0304
## 12 multiplicative gamma 0.000100
## 13 multiplicative l[0] 10.0
## 14 multiplicative b[0] -0.0114
## 15 multiplicative s[0] 0.943
## 16 multiplicative s[-1] 0.927
## 17 multiplicative s[-2] 0.969
## 18 multiplicative s[-3] 1.16
Adiditive Vs. Multiplicative
Measuring the quality of forecast method (forecast accuracy)
# Australia tourism
fit <- aus_holidays %>%
model(
ses = ETS(Trips ~ error("A") + trend("N") + season("N")),
additive = ETS(Trips ~ error("A") + trend("A") +
season("A")),
multiplicative = ETS(Trips ~ error("M") + trend("A") +
season("M"))
)
fc <- fit %>% forecast(h = "3 years")
fc %>%
autoplot(aus_holidays, level = NULL) +
labs(title="Australian domestic tourism",
y="Overnight trips (millions)") +
guides(colour = guide_legend(title = "Forecast"))

## Summary of measured quality for Australia tourism
aus_holidays %>%
stretch_tsibble(.init = 10) %>%
model(
ses = ETS(Trips ~ error("A") + trend("N") + season("N")),
additive = ETS(Trips ~ error("A") + trend("A") +
season("A")),
multiplicative = ETS(Trips ~ error("M") + trend("A") +
season("M")),
Damped = ETS(Trips ~ error("A") + trend("Ad") +
season("N"))
) %>%
forecast(h = 1) %>%
accuracy(aus_holidays)
## Warning: The future dataset is incomplete, incomplete out-of-sample data will be treated as missing.
## 1 observation is missing at 2018 Q1
## # A tibble: 4 x 10
## .model .type ME RMSE MAE MPE MAPE MASE RMSSE ACF1
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 additive Test 0.149 0.486 0.377 1.38 3.96 0.910 0.900 0.0507
## 2 Damped Test 0.129 1.06 0.812 0.278 8.24 1.96 1.97 -0.0802
## 3 multiplicative Test 0.144 0.475 0.369 1.34 3.87 0.889 0.881 0.0913
## 4 ses Test -0.0281 1.08 0.880 -1.50 9.15 2.12 1.99 0.0268
# Algeria_economy
fit_A <- algeria_economy %>%
model(
ses = ETS(Exports ~ error("A") + trend("N") + season("N")),
additive = ETS(Exports ~ error("A") + trend("A") +
season("A")),
multiplicative = ETS(Exports ~ error("M") + trend("A") +
season("M"))
)
## Warning: 1 error encountered for additive
## [1] A seasonal ETS model cannot be used for this data.
## Warning: 1 error encountered for multiplicative
## [1] A seasonal ETS model cannot be used for this data.
fc_A <- fit_A %>% forecast(h = "3 years")
fc_A %>%
autoplot(algeria_economy, level = NULL) +
labs(y = "Exports in % of GDP", title = "Algeria Exports of goods and services relatively to GDP from 1960 to 2017") +
guides(colour = guide_legend(title = "Forecast"))
## Warning: Removed 6 row(s) containing missing values (geom_path).

## Summary of measured quality Algeria_economy
# MAD = Mean absolute deviation
# MAPE = Mean absolute percentate error
# MSE = Mean squared error
# RMSE = Root mean squared error ...smaller = better
algeria_economy %>%
stretch_tsibble(.init = 10) %>%
model(
ses = ETS(Exports ~ error("A") + trend("N") + season("N")),
additive = ETS(Exports ~ error("A") + trend("A") +
season("A")),
multiplicative = ETS(Exports ~ error("M") + trend("A") +
season("M")),
Damped = ETS(Exports ~ error("A") + trend("Ad") +
season("N"))
) %>%
forecast(h = 1) %>%
accuracy(algeria_economy)
## Warning: 49 errors (1 unique) encountered for additive
## [49] A seasonal ETS model cannot be used for this data.
## Warning: 49 errors (1 unique) encountered for multiplicative
## [49] A seasonal ETS model cannot be used for this data.
## Warning: The future dataset is incomplete, incomplete out-of-sample data will be treated as missing.
## 1 observation is missing at 2018
## # A tibble: 4 x 11
## .model Country .type ME RMSE MAE MPE MAPE MASE RMSSE
## <chr> <fct> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 additive Algeria Test NaN NaN NaN NaN NaN NaN NaN
## 2 Damped Algeria Test 0.548 6.01 4.53 -0.808 16.6 1.09 1.01
## 3 multiplica~ Algeria Test NaN NaN NaN NaN NaN NaN NaN
## 4 ses Algeria Test -0.0195 5.36 4.01 -2.61 14.8 0.965 0.897
## # ... with 1 more variable: ACF1 <dbl>