Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating from bootstraps causing .rep clash #296

Closed
robjhyndman opened this issue Dec 18, 2020 · 3 comments
Closed

Generating from bootstraps causing .rep clash #296

robjhyndman opened this issue Dec 18, 2020 · 3 comments
Milestone

Comments

@robjhyndman
Copy link
Member

library(fable)
library(feasts)
library(dplyr)

data <- USAccDeaths %>%
  as_tsibble()
stl <- data %>%
  model(stl = STL(value))
# Bootstrap variants of the data
sim <- stl %>% 
  generate(new_data = data, times=3) %>%
  select(-.model)
# Fit models to each bootstrap variant
simulated_fits <- sim %>%
  model(ets = ETS(.sim)) 
# Generate future sample paths from each model
simulated_fits %>% 
  generate(h=10, times=20)
#> New names:
#> * .rep -> .rep...1
#> * .rep -> .rep...4
#> Error: Can't subset columns that don't exist.
#> x Columns `.rep` and `.rep` don't exist.

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

Because .rep is part of the key structure, just renaming it also causes problems.

@mitchelloharawild mitchelloharawild added this to the v0.2.2 milestone Jan 4, 2021
@mitchelloharawild
Copy link
Member

The key structure needs to update for the conflict resolving column names done by {vctrs} - not sure why this isn't happening yet.

However in the short term, renaming should work without issue:

library(fable)
#> Loading required package: fabletools
library(feasts)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

data <- USAccDeaths %>%
  as_tsibble()
stl <- data %>%
  model(stl = STL(value))
# Bootstrap variants of the data
sim <- stl %>% 
  generate(new_data = data, times=3)
# Fit models to each bootstrap variant
simulated_fits <- sim %>%
  # This can be changed at the tsibble level, or later...
  # rename(variant = .rep) %>% 
  model(ets = ETS(.sim)) 
# Generate future sample paths from each model
simulated_fits %>% 
  # Additionally we can retain the model identifier for the bootstrap if we desire
  rename(variant = .rep, bootstrap_model = .model) %>%
  generate(h=10, times=20)
#> # A tsibble: 600 x 6 [1M]
#> # Key:       bootstrap_model, variant, .model, .rep [60]
#>    bootstrap_model variant .model    index .rep    .sim
#>    <chr>           <chr>   <chr>     <mth> <chr>  <dbl>
#>  1 stl             1       ets    1979 Jan 1      8085.
#>  2 stl             1       ets    1979 Feb 1      7408.
#>  3 stl             1       ets    1979 Mar 1      8398.
#>  4 stl             1       ets    1979 Apr 1      8600.
#>  5 stl             1       ets    1979 May 1      8978.
#>  6 stl             1       ets    1979 Jun 1     10061.
#>  7 stl             1       ets    1979 Jul 1     10491.
#>  8 stl             1       ets    1979 Aug 1     10067.
#>  9 stl             1       ets    1979 Sep 1      8826.
#> 10 stl             1       ets    1979 Oct 1      8953.
#> # … with 590 more rows

Created on 2021-01-07 by the reprex package (v0.3.0)

@mitchelloharawild
Copy link
Member

Related MRE:

library(fable)
#> Loading required package: fabletools
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
mdl <- as_tsibble(cbind(mdeaths, fdeaths)) %>% 
  model(SNAIVE(value))
bind_cols(mdl, as_tibble(mdl)["key"])
#> New names:
#> * key -> key...1
#> * key -> key...3
#> Error: Can't subset columns that don't exist.
#> x Column `key` doesn't exist.

Created on 2021-01-07 by the reprex package (v0.3.0)

@mitchelloharawild
Copy link
Member

Consolidating with #275

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants