business-science/sweep

Warning in tzone, length > 1 only first element will be used

mdancho84 opened this issue · 1 comments

library(tidyquant)
library(timekit)
library(forecast)
library(sweep)

# Create sample data
ts <- c(1500256800, 1500260400, 1500264000, 1500267600) %>%
    as_datetime() %>%
    tk_make_future_timeseries(n_future = 30)

y <- 4 * sin(seq(0, 6*pi, length.out = 30)) + rnorm(30)

df <- tibble(
    timestamp = ts,
    y = y
)
df
#> # A tibble: 30 x 2
#>              timestamp          y
#>                 <dttm>      <dbl>
#>  1 2017-07-17 06:00:00  0.2469198
#>  2 2017-07-17 07:00:00  1.3693633
#>  3 2017-07-17 08:00:00  3.4791324
#>  4 2017-07-17 09:00:00  5.8790111
#>  5 2017-07-17 10:00:00  2.0144353
#>  6 2017-07-17 11:00:00 -0.3075964
#>  7 2017-07-17 12:00:00 -3.1721463
#>  8 2017-07-17 13:00:00 -4.4677288
#>  9 2017-07-17 14:00:00 -2.7972492
#> 10 2017-07-17 15:00:00 -0.7959438
#> # ... with 20 more rows

# Make ts
ts_frequency <- 24

start <- 1

tk_ts_dataframe <- tk_ts(df, start = start, freq = ts_frequency, silent = TRUE)

# auto.arima
fit <- auto.arima(tk_ts_dataframe, trace = TRUE, stepwise = FALSE)
#> 
#>  ARIMA(0,0,0)            with zero mean     : 153.7608
#>  ARIMA(0,0,0)            with non-zero mean : 156.0597
#>  ARIMA(0,0,1)            with zero mean     : 136.3618
#>  ARIMA(0,0,1)            with non-zero mean : 138.8296
#>  ARIMA(0,0,2)            with zero mean     : 129.4083
#>  ARIMA(0,0,2)            with non-zero mean : 132.0502
#>  ARIMA(0,0,3)            with zero mean     : 128.1603
#>  ARIMA(0,0,3)            with non-zero mean : 130.9836
#>  ARIMA(0,0,4)            with zero mean     : Inf
#>  ARIMA(0,0,4)            with non-zero mean : Inf
#>  ARIMA(0,0,5)            with zero mean     : 131.5894
#>  ARIMA(0,0,5)            with non-zero mean : 134.8756
#>  ARIMA(1,0,0)            with zero mean     : 134.9487
#>  ARIMA(1,0,0)            with non-zero mean : 137.4262
#>  ARIMA(1,0,1)            with zero mean     : 132.4469
#>  ARIMA(1,0,1)            with non-zero mean : 135.1224
#>  ARIMA(1,0,2)            with zero mean     : 130.6951
#>  ARIMA(1,0,2)            with non-zero mean : 133.5951
#>  ARIMA(1,0,3)            with zero mean     : 131.5027
#>  ARIMA(1,0,3)            with non-zero mean : 134.612
#>  ARIMA(1,0,4)            with zero mean     : 131.5963
#>  ARIMA(1,0,4)            with non-zero mean : Inf
#>  ARIMA(2,0,0)            with zero mean     : 125.5597
#>  ARIMA(2,0,0)            with non-zero mean : 128.2366
#>  ARIMA(2,0,1)            with zero mean     : 112.2001
#>  ARIMA(2,0,1)            with non-zero mean : 115.0497
#>  ARIMA(2,0,2)            with zero mean     : Inf
#>  ARIMA(2,0,2)            with non-zero mean : Inf
#>  ARIMA(2,0,3)            with zero mean     : Inf
#>  ARIMA(2,0,3)            with non-zero mean : Inf
#>  ARIMA(3,0,0)            with zero mean     : 115.0323
#>  ARIMA(3,0,0)            with non-zero mean : 117.9296
#>  ARIMA(3,0,1)            with zero mean     : 105.2365
#>  ARIMA(3,0,1)            with non-zero mean : 108.2996
#>  ARIMA(3,0,2)            with zero mean     : Inf
#>  ARIMA(3,0,2)            with non-zero mean : Inf
#>  ARIMA(4,0,0)            with zero mean     : 102.6375
#>  ARIMA(4,0,0)            with non-zero mean : 105.405
#>  ARIMA(4,0,1)            with zero mean     : 104.4866
#>  ARIMA(4,0,1)            with non-zero mean : 107.3057
#>  ARIMA(5,0,0)            with zero mean     : 103.1069
#>  ARIMA(5,0,0)            with non-zero mean : 106.3176

# Forecast
forecast_duration <- 10
fc <- forecast(fit, h = forecast_duration)

# Sweep: has warning message
final <- sw_sweep(fc, timekit_idx = TRUE)
#> Warning in if (!(tclass %in% c("yearmon", "yearqtr"))) lubridate::tz(ret)
#> <- tzone: the condition has length > 1 and only the first element will be
#> used

Will need to upgrade to timetk v0.1.0 and sweep v0.2.0.

# This works with no warning
final <- sw_sweep(fc, timekit_idx = TRUE)