I an trying to use your code for a univariate time series I generated and I am running into some problems relating to "missing values not supported". Could you please take a look at this if you have time?
#load libraries
devtools::install_github("ahaeusser/echos")
devtools::install_github("ahaeusser/tscv")
install.packages("fable")
remotes::install_github("tidyverts/fable")
remotes::install_github("tidyverts/tsibble")
#load libraries
library(echos)
library(tscv)
library(dplyr)
library(tsibble)
library(fabletools)
library(fable)
Sys.setlocale("LC_TIME", "C")
#> [1] "C"
library(lubridate)
library(dplyr)
library(tibble)
library(tsibble)
date_decision_made = seq(as.Date("1800/1/1"), as.Date("2020/1/1"),by="day")
date_decision_made <- format(as.Date(date_decision_made), "%Y/%m/%d")
property_damages_in_dollars <- rnorm( 80354,100,10)
final_data <- data.frame(date_decision_made, property_damages_in_dollars)
mut = final_data %>%
mutate(date_decision_made = as.Date(date_decision_made)) %>%
group_by(week = format(date_decision_made, "%Y-%m")) %>%
summarise( total = sum(property_damages_in_dollars, na.rm = TRUE))
#pretend the data has been sampled for "training" and "testing"
sample1 <- c("train","test" )
mut$status<- sample(sample1 , 2641 , replace=TRUE, prob=c(0.7, 0.3))
mut$status <- as.factor(mut$status)
mut$Value = mut$total
mut$total = NULL
ym <- function (..., quiet = FALSE, tz = NULL, locale = Sys.getlocale("LC_TIME")) {
lubridate:::.parse_xxx(..., orders = "ym", quiet = quiet, tz = tz, locale = locale,
truncated = 0)
}
mut$week <- ym(mut$week)
tibble <- as.tibble(mut)
z = tibble %>%
as_tsibble(index = week)
data = z
# Setup for time series cross validation
n_init <- 2400 # size for training window
n_ahead <- 24 # size for testing window (forecast horizon)
mode <- "slide" # fixed window approach
n_skip <- 23 # skip 23 observations
n_lag <- 0 # no lag
data <- data %>%
tscv::split_data(
n_init = n_init,
n_ahead = n_ahead,
mode = mode,
n_skip = n_skip,
n_lag = n_lag)
models <- data %>%
filter(sample == "train") %>%
model(
"ESN" = ESN(
Value,
inf_crit = "BIC",
max_lag = 6,
n_fourier = c(3, 3),
n_initial = 50,
n_res = 200,
scale_inputs = c(-1, 1)),
"sNaive" = SNAIVE(Value ~ lag("week")))
Warning messages:
1: 11 errors (1 unique) encountered for ESN
[11] cannot coerce type 'closure' to vector of type 'double'
2: 11 errors (1 unique) encountered for sNaive
[11] .data contains implicit gaps in time. You should check your data and convert implicit gaps into explicit missing values using `tsibble::fill_gaps()` if required.
data <- data %>%
fill_gaps(.full = TRUE)
But the same error happens. This error is preventing me from running the rest of the code:
[models <- data %>%
filter(sample == "train") %>%
model(
"ESN" = ESN(
Value,
inf_crit = "BIC",
max_lag = 6,
n_fourier = c(3, 3),
n_initial = 50,
n_res = 200,
scale_inputs = c(-1, 1)),
"sNaive" = SNAIVE(Value ~ lag("week")))
## Detailed report of ESN
models %>%
select(ESN) %>%
report()
# Forecast models
fcsts <- models %>%
forecast(h = n_ahead)
actuals <- data %>%
filter_index("2019-04-10" ~ .)
fcsts %>%
autoplot(
actuals,
level = NULL,
size = 1)](url)
Could you please take a look at this if you have time? Perhaps I am doing something wrong and you could kindly show me how to fix this problem?