-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathweek6.R
110 lines (86 loc) · 1.91 KB
/
week6.R
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
library(fpp3)
## Example: Australian holiday tourism by Region
holidays <- tourism |>
filter(Purpose == "Holiday")
fit <- holidays |>
model(ets = ETS(Trips))
fit |>
filter(Region == "Snowy Mountains") |>
report()
fit |>
filter(Region == "Snowy Mountains") |>
components(fit) |>
autoplot()
fit |>
filter(Region == "Snowy Mountains") |>
forecast() |>
autoplot(holidays, show_gap = FALSE) +
xlab("Year") + ylab("Overnight trips (thousands)")
# Sum over regions
aus_holidays <- tourism |>
filter(Purpose == "Holiday") |>
summarise(Trips = sum(Trips))
aus_holidays |> autoplot()
fit <- aus_holidays |>
model(
additive = ETS(Trips ~ error("A") + trend("A") + season("A")),
multiplicative = ETS(Trips ~ error("M") + trend("A") + season("M")),
auto = ETS(Trips)
)
fit |>
select(multiplicative) |>
report()
components(fit) |> autoplot()
fit |>
select(multiplicative) |>
components() |>
autoplot()
fit |> augment()
residuals(fit)
residuals(fit, type = "innov")
fit |>
select(multiplicative) |>
gg_tsresiduals()
fc <- fit |> forecast()
fc |>
autoplot(aus_holidays) + xlab("Year") +
ylab("Overnight trips (thousands)")
## H02
h02 <- PBS |>
filter(ATC2 == "H02") |>
summarise(Cost = sum(Cost))
h02 |>
autoplot(Cost)
h02 |>
model(ETS(Cost)) |>
report()
h02 |>
model(ETS(Cost ~ error("A") + trend("A") + season("A"))) |>
report()
h02 |>
model(ETS(Cost)) |>
forecast() |>
autoplot(h02)
fit <- h02 |>
model(
auto = ETS(Cost),
AAA = ETS(Cost ~ error("A") + trend("A") + season("A")),
damped = ETS(Cost ~ trend("Ad")),
forbidden = ETS(Cost ~ error("A") + trend("Ad") + season("M"))
)
fit |> glance()
fit |> accuracy()
fit |> tidy()
# Example of STL + ETS
stl_fit <- h02 |>
model(
decomposition_model(
STL(Cost),
ETS(season_adjust),
SNAIVE(season_year)
)
)
stl_fit |> report()
stl_fit |>
forecast(h = 24) |>
autoplot(h02)