Closed mitchelloharawild closed 5 years ago
Should work fine now.
library(tsibble)
library(tidyverse)
library(feasts)
#> Loading required package: fablelite
AirPass <- as_tsibble(AirPassengers) %>% rename(month = index, pass = value)
## test for seasonal differencing first
AirPass %>%
features(log(pass), unitroot_nsdiffs) # reports minimum seasonal differences = 1
#> # A tibble: 1 x 1
#> nsdiffs
#> <int>
#> 1 1
## perform one seasonal differencing and then test for first differencing
AirPass %>%
mutate(SDpass = difference(log(pass), lag = 12)) %>%
features(SDpass, unitroot_ndiffs) # reports minimum first differences = 0
#> # A tibble: 1 x 1
#> ndiffs
#> <int>
#> 1 0
## if you test for first differencing first
AirPass %>%
features(log(pass), unitroot_ndiffs) # reports minimum first differences = 1
#> # A tibble: 1 x 1
#> ndiffs
#> <int>
#> 1 1
## perform a first differencing and then test for seasonal differencing
AirPass %>%
mutate(Dpass = difference(log(pass), lag = 1)) %>%
features(Dpass, unitroot_nsdiffs) # the output is just a blank row
#> # A tibble: 1 x 1
#> nsdiffs
#> <int>
#> 1 1
## If I filter out the NA in the first row from the first differencing…
AirPass %>%
mutate(Dpass = difference(log(pass), lag = 1)) %>%
slice(2:nrow(AirPass)) %>%
features(Dpass, unitroot_nsdiffs) # reports minimum seasonal differences = 1
#> # A tibble: 1 x 1
#> nsdiffs
#> <int>
#> 1 1
Created on 2019-07-22 by the reprex package (v0.3.0)
Created on 2019-07-17 by the reprex package (v0.3.0)