tidyverts / fabletools

General fable features useful for extension packages
http://fabletools.tidyverts.org/
89 stars 31 forks source link

autoplot fails with multivariate timeseries and new_data in forecast #284

Closed TylerGrantSmith closed 3 years ago

TylerGrantSmith commented 3 years ago
library(tsibble)
library(fable)
#> Loading required package: fabletools

set.seed(40)
x = rnorm(24, 1)
y = rnorm(24, 30)

xy = data.frame(x,y)
train = as_tsibble(ts(xy, frequency = 12, start = c(2020, 1)), pivot_longer = FALSE)
test  = as_tsibble(ts(xy, frequency = 12, start = c(2022, 1)), pivot_longer = FALSE)

fit <- train %>% model(VAR(vars(x,y) ~ AR(1)))

# works
fc <- forecast(fit)
autoplot(fc)


# doesn't work
fc <- forecast(fit, new_data = test)
autoplot(fc)
#> Error: Names must be unique.
#> x These names are duplicated:
#>   * "x" at locations 6 and 8.
#>   * "y" at locations 7 and 9.
#> i Use argument `names_repair` to specify repair strategy.

Created on 2020-10-12 by the reprex package (v0.3.0)

mitchelloharawild commented 3 years ago

Thanks! Should work now:

library(tsibble)
library(fable)
#> Loading required package: fabletools

set.seed(40)
x = rnorm(24, 1)
y = rnorm(24, 30)

xy = data.frame(x,y)
train = as_tsibble(ts(xy, frequency = 12, start = c(2020, 1)), pivot_longer = FALSE)
test  = as_tsibble(ts(xy, frequency = 12, start = c(2022, 1)), pivot_longer = FALSE)

fit <- train %>% model(VAR(vars(x,y) ~ AR(1)))

# works
fc <- forecast(fit)
autoplot(fc)


# doesn't work
fc <- forecast(fit, new_data = test)
autoplot(fc)

Created on 2020-10-14 by the reprex package (v0.3.0)