Last active
March 4, 2020 13:56
-
-
Save bdemeshev/e1d2e8b84632145249107aba7f63311d to your computer and use it in GitHub Desktop.
Time series, ranepa, spring 2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(fable) | |
library(feasts) | |
library(lubridate) | |
library(tidyverse) | |
AirPassengers | |
class(AirPassengers) # старый добрый ts формат | |
AirPassengers | |
ap = as_tsibble(AirPassengers) # переделали в стильный tsibble формат | |
# график | |
autoplot(ap, value) + | |
labs(x = "Период", | |
y = "Число пассажиров (тыс чел/мес)") + | |
ggtitle("Пассажиропоток") | |
# отбор наблюдений | |
ap2 = filter(ap, index > "1952-04-07") | |
# создание нового ряда: | |
ap3 = mutate(ap, log_pax = log(value), | |
pax2 = value^2, | |
pax_1 = lag(value)) | |
head(ap3) | |
autoplot(ap3, log_pax) | |
mtable = model(ap, | |
rand_walk = NAIVE(value), | |
ma_1 = ARIMA(value ~ pdq(0, 0, 1) + PDQ(0, 0, 0)), | |
ets = ETS(value)) | |
mtable | |
mtable$rand_walk[[1]] | |
mtable$ma_1[[1]] | |
fcst = forecast(mtable, h = "2 years") | |
autoplot(fcst, ap) | |
fcst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(fable) | |
library(feasts) | |
library(tidyverse) | |
AirPassengers | |
?AirPassengers | |
class(AirPassengers) | |
ap = as_tsibble(AirPassengers) | |
ap | |
autoplot(ap, value) | |
# создание новых переменных | |
ap2 = mutate(ap, log_pax = log(value), | |
pax2 = value^2, | |
pax_1 = lag(value), | |
d_pax = value - lag(value)) | |
head(ap2) | |
# усечение куска ряда | |
ap3 = filter(ap, index > "1953-06-20") | |
head(ap3) | |
mtable = model(ap, | |
rand_walk = NAIVE(value), | |
ets = ETS(value)) | |
mtable$rand_walk[[1]] | |
fcst = forecast(mtable, h = "2 years") | |
fcst | |
autoplot(fcst, ap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(fable) | |
library(feasts) | |
library(tidyverse) | |
devtools::install_github("tidyverts/fable") | |
air = as_tsibble(AirPassengers) | |
glimpse(air) | |
autoplot(air, value) | |
air_train = filter(air, index < "1959-01-01") | |
models = model(air_train, | |
ar1 = ARIMA(value ~ pdq(1, 0, 0) + PDQ(0, 0, 0)), | |
ma1 = ARIMA(value ~ pdq(0, 0, 1) + PDQ(0, 0, 0)), | |
ann = ETS(value ~ error("A") + trend("N") + season("N")), | |
aaa = ETS(value ~ error("A") + trend("A") + season("A")), | |
ets = ETS(value)) | |
fcst = forecast(models, h = "2 years") | |
fcst | |
fcst %>% filter(.model == "ar1") %>% autoplot(air) | |
accuracy(fcst, air) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment