-
Notifications
You must be signed in to change notification settings - Fork 167
/
week3.R
65 lines (49 loc) · 1.42 KB
/
week3.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
library(fpp3)
# Find a transformation for the following
global_economy |>
filter(Country == "United States") |>
autoplot(GDP)
aus_livestock |>
filter(Animal == "Bulls, bullocks and steers", State == "Victoria") |>
autoplot(Count)
vic_elec |>
autoplot(Demand)
aus_production |>
autoplot(Gas)
canadian_gas |>
autoplot(Volume)
## US retail employment ----------------------------------------------------------
us_retail_employment <- us_employment |>
filter(year(Month) >= 1990, Title == "Retail Trade") |>
select(-Series_ID)
us_retail_employment |>
autoplot(Employed) +
labs(
y = "Persons (thousands)",
title = "Total employment in US retail"
)
dcmp <- us_retail_employment |>
model(stl = STL(Employed))
dcmp |>
components() |>
autoplot()
components(dcmp) |> gg_subseries(season_year)
us_retail_employment |>
autoplot(Employed, color = "gray") +
autolayer(components(dcmp), trend, color = "red") +
labs(
y = "Persons (thousands)",
title = "Total employment in US retail"
)
us_retail_employment |>
autoplot(Employed, color = "gray") +
autolayer(components(dcmp), season_adjust, color = "blue") +
labs(
y = "Persons (thousands)",
title = "Total employment in US retail"
)
us_retail_employment |>
model(STL(Employed ~ season(window = 13) + trend(window = 7), robust = TRUE)) |>
components() |>
autoplot() +
labs(title = "STL decomposition: US retail employment")