-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathweek2.R
144 lines (111 loc) · 2.9 KB
/
week2.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
library(fpp3)
## LOTS OF EXAMPLES -------------------------------------------------------------
aus_production |>
filter(year(Quarter) >= 1980) |>
autoplot(Electricity) +
labs(
y = "GWh",
title = "Australian electricity production"
)
aus_production |>
autoplot(Tobacco) +
labs(
title = "Australian tobacco production",
y = "million units"
)
aus_production |>
autoplot(Bricks) +
labs(
title = "Australian clay brick production",
y = "million units"
)
us_employment |>
filter(Title == "Retail Trade", year(Month) >= 1980) |>
autoplot(Employed / 1e3) +
labs(
title = "Retail employment, USA",
y = "Million people"
)
gafa_stock |>
filter(Symbol == "AMZN", year(Date) >= 2018) |>
autoplot(Close) +
labs(
title = "Amazon closing stock price",
y = "$US"
)
gafa_stock |>
filter(Symbol == "AMZN", year(Date) >= 2018) |>
ggplot(aes(x = Date, y = Close)) +
geom_line() +
labs(
title = "Amazon closing stock price",
y = "$US"
)
## Snowy mountains tourism -------------------------------------------------------------------------
snowy <- tourism |>
filter(Region == "Snowy Mountains") |>
summarise(Trips = sum(Trips))
snowy |> autoplot(Trips)
snowy |> gg_season(Trips, labels="both")
snowy |> gg_subseries(Trips)
snowy |> gg_lag(Trips)
snowy |> gg_lag(Trips, geom = "point", lags = 1:16)
snowy |> ACF(Trips, lag_max = 16)
snowy |>
ACF(Trips, lag_max = 20) |>
autoplot()
snowy |>
ACF(Trips) |>
autoplot()
## RETAIL TRADE ------------------------------------------------------------------
retail <- us_employment |>
filter(Title == "Retail Trade", year(Month) >= 1980)
retail |> autoplot(Employed)
retail |>
ACF(Employed, lag_max = 48) |>
autoplot()
# Pelts
pelt |>
autoplot(Lynx) +
labs(
title = "Annual Canadian Lynx Trappings",
y = "Number trapped"
)
pelt |>
ACF(Lynx, lag_max = 25) |>
autoplot()
## WHITE NOISE --------------------------------------------------------------------
set.seed(30)
wn <- tsibble(t = seq(50), y = rnorm(50), index = t)
wn |> autoplot(y)
wn |> ACF(y, lag_max = 10)
wn |> ACF(y) |> autoplot()
## PIGS ---------------------------------------------------------------------------
pigs <- aus_livestock |>
filter(
State == "Victoria", Animal == "Pigs",
year(Month) >= 2014
)
pigs |> autoplot(Count / 1e3) +
labs(
y = "Thousands",
title = "Number of pigs slaughtered in Victoria"
)
pigs |>
ACF(Count, lag_max = 36) |>
autoplot()
## Google 2015 -------------------------------------------------------------------
google_2015 <- gafa_stock |>
filter(Symbol == "GOOG", year(Date) == 2015) |>
select(Date, Close)
google_2015 |> autoplot(Close)
google_2015 |>
ACF(Close, lag_max = 100) |>
autoplot()
google_2015 |>
mutate(diff = difference(Close)) |>
autoplot(diff)
google_2015 |>
mutate(diff = difference(Close)) |>
ACF(diff, lag_max = 100) |>
autoplot()