library(fpp3)
library(tsibble)
library(cowplot)
global_economy %>%
autoplot(GDP/Population,show.legend=F) +
labs(title= "GDP per capita", y = "$US")
global_economy %>% mutate(sum = GDP/Population) %>% as.tibble() %>%
group_by(Country) %>% summarise(Largest_GDP = sum(sum, na.rm = T)) %>% slice_max(Largest_GDP,n=2)
global_economy %>%
filter(Country %in% c("Monaco","Liechtenstein")) %>%
autoplot(GDP/Population) +
labs(title= "GDP per capita In Monaco and Liechtenstein", y = "$US")
global_economy %>%
filter(Country == "United States") %>%
autoplot(GDP/Population,show.legend=F) +
labs(title= "GDP per capita In the United States", y = "$US")
| For the slaughter data, we add a moving average to smooth out the trend line in order to have a better understanding of the overall average change overtime.
aus_livestock %>% filter(Animal=="Bulls, bullocks and steers" & State =="Victoria") %>%
mutate(
`5-MA` = slider::slide_dbl(Count, mean,
.before = 12, .after = 12, .complete = TRUE)
) %>% autoplot(Count) +
geom_line(aes(y = `5-MA`), colour = "#D55E00") +
labs( title = "Slaughter of Livestock")
vic_elec %>%
model( STL(Demand)) %>%
components() %>% autoplot()
aus_production %>% autoplot(Gas)
lambda <- aus_production %>%
features(Gas, features = guerrero) %>%
pull(lambda_guerrero)
aus_production %>%
autoplot(box_cox(Gas, lambda)) +
labs(y = "",
title = latex2exp::TeX(paste0(
"Transformed gas production with $\\lambda$ = ",
round(lambda,2))))
canadian_gas %>% autoplot()
lambda_ca <- canadian_gas %>%
features(Volume, features = guerrero) %>%
pull(lambda_guerrero)
canadian_gas %>%
autoplot(box_cox(Volume, lambda_ca)) +
labs(y = "",
title = latex2exp::TeX(paste0(
"Transformed gas production with $\\lambda$ = ",
round(lambda_ca,2))))
set.seed(1221)
myseries <- aus_retail %>%
filter(`Series ID` == sample(aus_retail$`Series ID`,1))
autoplot(myseries,Turnover)
lambda_retail <- myseries %>%
features(Turnover, features = guerrero) %>%
pull(lambda_guerrero)
myseries %>%
autoplot(box_cox(Turnover, lambda_retail)) +
labs(y = "",
title = latex2exp::TeX(paste0(
"Transformed retail turnover with $\\lambda$ = ",
round(lambda_retail,2))))
aus_production %>%
autoplot(Tobacco)
lambda_tob <- aus_production %>%
features(Tobacco, features = guerrero) %>%
pull(lambda_guerrero)
aus_production %>%
autoplot(box_cox(Tobacco, lambda_tob)) +
labs(y = "",
title = latex2exp::TeX(paste0(
"Transformed Tobacco Production with $\\lambda$ = ",
round(lambda_tob,2))))
ansett %>% filter(Class=="Economy" & Airports == "MEL-SYD") %>% autoplot()
lambda_pass <- ansett %>% filter(Class=="Economy" & Airports == "MEL-SYD") %>%
features(Passengers, features = guerrero) %>%
pull(lambda_guerrero)
ansett %>% filter(Class=="Economy" & Airports == "MEL-SYD") %>%
autoplot(box_cox(Passengers, lambda_pass)) +
labs(y = "",
title = latex2exp::TeX(paste0(
"Transformed Economy Passngr Rate from Melbourne to Sydney with $\\lambda$ = ",
round(lambda_pass,2))))
pedestrian %>%
filter(Sensor=="Southern Cross Station") %>%
autoplot(Count)
lamb_ped <- pedestrian %>%
filter(Sensor=="Southern Cross Station") %>%
features(Count, features = guerrero) %>%
pull(lambda_guerrero)
pedestrian %>%
filter(Sensor=="Southern Cross Station") %>%
autoplot(box_cox(Count, lamb_ped)) +
labs(y = "",
title = latex2exp::TeX(paste0(
"Transformed Pedestrian Counts with $\\lambda$ = ",
round(lamb_ped,2))))
gas <- tail(aus_production, 5*4) %>% select(Gas)
Ass seen below, we can see a clear seasonal trend occurring. However, it is certainly difficult to pinpoint the exact Quarter it begins and ends on.
gas %>% autoplot()
gas %>%
model(
classical_decomposition(Gas, type = "additive")
) %>%
components() %>%
autoplot() +
labs(title = "Classical additive decomposition of total
Gas Production ")
gas %>%
model( STL(Gas)) %>%
components() %>% as_tsibble() %>%
autoplot(Gas, colour = "gray") +
geom_line(aes(y=season_adjust), colour = "#0072B2") +
labs( title = "Seasonally Adjusted Gas Production")
## e.
gas[5,1] <- 300
gas %>%
model( STL(Gas)) %>%
components() %>% as_tsibble() %>%
autoplot(Gas, colour = "gray") +
geom_line(aes(y=season_adjust), colour = "#0072B2") +
labs( title = "Seasonally Adjusted Gas Production with outlier")
mid <- tail(aus_production, 5*4) %>% select(Gas)
mid[10,1] <- 300
mid %>%
model( STL(Gas)) %>%
components() %>% as_tsibble() %>%
autoplot(Gas, colour = "gray") +
geom_line(aes(y=season_adjust), colour = "#0072B2") +
labs( title = "Seasonally Adjusted Gas Production with outlier in middle" )
end <- tail(aus_production, 5*4) %>% select(Gas)
end[20,1] <- 300
end %>%
model( STL(Gas)) %>%
components() %>% as_tsibble() %>%
autoplot(Gas, colour = "gray") +
geom_line(aes(y=season_adjust), colour = "#0072B2") +
labs( title = "Seasonally Adjusted Gas Production with outlier at end")
myseries %>%
model(x11 = X_13ARIMA_SEATS(Turnover ~ x11())) %>%
components() %>% autoplot()