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

Can't use forecast after reconcile #374

Open
ruqianchen opened this issue Jan 6, 2023 · 2 comments
Open

Can't use forecast after reconcile #374

ruqianchen opened this issue Jan 6, 2023 · 2 comments

Comments

@ruqianchen
Copy link

The sample code here https://fabletools.tidyverts.org/reference/reconcile.html no longer works. When I ran it, I received the message " no applicable method for 'forecast'".

Details:

> library(fable)
> lung_deaths_agg <- as_tsibble(cbind(mdeaths, fdeaths)) %>%
+   aggregate_key(key, value = sum(value))
> 
> lung_deaths_agg %>%
+   model(lm = TSLM(value ~ trend() + season())) %>%
+   reconcile(lm = min_trace(lm)) %>% 
+   forecast()
Error in UseMethod("forecast") : 
  no applicable method for 'forecast' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"

Thanks!

@ruqianchen
Copy link
Author

ruqianchen commented Jan 6, 2023

For reference, the intermediate step output is a tibble with no time column to use as index for the tsibble that forecast requires.

> lung_deaths_agg %>%
+   model(lm = TSLM(value ~ trend() + season())) %>%
+   reconcile(lm = min_trace(lm))
# A tibble: 3 × 2
  key          lm     
  <chr>        <model>
1 fdeaths      <TSLM> 
2 mdeaths      <TSLM> 
3 <aggregated> <TSLM> 

@mitchelloharawild
Copy link
Member

I am unable to reproduce this issue, could you please check that your packages are up to date? If they are, please provide your session info with a reprex via reprex::reprex(si = TRUE).

library(fable)
#> Loading required package: fabletools
lung_deaths_agg <- as_tsibble(cbind(mdeaths, fdeaths)) %>%
   aggregate_key(key, value = sum(value))

lung_deaths_agg %>%
  model(lm = TSLM(value ~ trend() + season())) %>%
  reconcile(lm = min_trace(lm)) %>% 
  forecast()
#> Loading required namespace: crayon
#> # A fable: 72 x 5 [1M]
#> # Key:     key, .model [3]
#>    key     .model    index        value .mean
#>    <chr*>  <chr>     <mth>       <dist> <dbl>
#>  1 fdeaths lm     1980 Jan N(794, 5606)  794.
#>  2 fdeaths lm     1980 Feb N(778, 5606)  778.
#>  3 fdeaths lm     1980 Mar N(737, 5606)  737.
#>  4 fdeaths lm     1980 Apr N(577, 5606)  577.
#>  5 fdeaths lm     1980 May N(456, 5606)  456.
#>  6 fdeaths lm     1980 Jun N(386, 5606)  386.
#>  7 fdeaths lm     1980 Jul N(379, 5606)  379.
#>  8 fdeaths lm     1980 Aug N(335, 5606)  335.
#>  9 fdeaths lm     1980 Sep N(340, 5606)  340.
#> 10 fdeaths lm     1980 Oct N(413, 5606)  413.
#> # … with 62 more rows

Created on 2023-01-09 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       Ubuntu 20.04.4 LTS
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en_AU:en
#>  collate  en_AU.UTF-8
#>  ctype    en_AU.UTF-8
#>  tz       Australia/Melbourne
#>  date     2023-01-09
#>  pandoc   2.19.2 @ /usr/lib/rstudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package        * version    date (UTC) lib source
#>  anytime          0.3.9      2020-08-27 [1] RSPM (R 4.1.2)
#>  assertthat       0.2.1      2019-03-21 [1] RSPM (R 4.1.2)
#>  cli              3.5.0      2022-12-20 [1] CRAN (R 4.1.2)
#>  colorspace       2.0-3      2022-02-21 [1] RSPM (R 4.1.2)
#>  crayon           1.5.2      2022-09-29 [1] CRAN (R 4.1.2)
#>  DBI              1.1.3      2022-06-18 [1] CRAN (R 4.1.2)
#>  digest           0.6.31     2022-12-11 [1] CRAN (R 4.1.2)
#>  distributional   0.3.1.9000 2023-01-09 [1] Github (mitchelloharawild/distributional@50e2955)
#>  dplyr            1.0.10     2022-09-01 [1] CRAN (R 4.1.2)
#>  ellipsis         0.3.2      2021-04-29 [1] RSPM (R 4.1.2)
#>  evaluate         0.17       2022-10-07 [1] CRAN (R 4.1.2)
#>  fable          * 0.3.2.9000 2023-01-09 [1] local
#>  fabletools     * 0.3.2.9000 2023-01-09 [1] local
#>  fansi            1.0.3      2022-03-24 [1] RSPM (R 4.1.2)
#>  farver           2.1.1      2022-07-06 [1] CRAN (R 4.1.2)
#>  fastmap          1.1.0      2021-01-25 [1] RSPM (R 4.1.2)
#>  fs               1.5.2      2021-12-08 [1] CRAN (R 4.1.2)
#>  generics         0.1.3      2022-07-05 [1] CRAN (R 4.1.2)
#>  ggplot2          3.4.0      2022-11-04 [1] CRAN (R 4.1.2)
#>  glue             1.6.2      2022-02-24 [1] CRAN (R 4.1.2)
#>  gtable           0.3.1      2022-09-01 [1] CRAN (R 4.1.2)
#>  highr            0.9        2021-04-16 [1] RSPM (R 4.1.2)
#>  htmltools        0.5.3      2022-07-18 [1] CRAN (R 4.1.2)
#>  knitr            1.41       2022-11-18 [1] CRAN (R 4.1.2)
#>  lattice          0.20-45    2021-09-22 [2] CRAN (R 4.1.2)
#>  lifecycle        1.0.3      2022-10-07 [1] CRAN (R 4.1.2)
#>  lubridate        1.9.0      2022-11-06 [1] CRAN (R 4.1.2)
#>  magrittr         2.0.3      2022-03-30 [1] RSPM (R 4.1.2)
#>  Matrix           1.4-1      2022-03-23 [1] CRAN (R 4.1.2)
#>  munsell          0.5.0      2018-06-12 [1] RSPM (R 4.1.2)
#>  pillar           1.8.1      2022-08-19 [1] CRAN (R 4.1.2)
#>  pkgconfig        2.0.3      2019-09-22 [1] RSPM (R 4.1.2)
#>  progressr        0.12.0     2022-12-13 [1] CRAN (R 4.1.2)
#>  purrr            1.0.0      2022-12-20 [1] CRAN (R 4.1.2)
#>  R6               2.5.1      2021-08-19 [1] CRAN (R 4.1.2)
#>  Rcpp             1.0.9      2022-07-08 [1] CRAN (R 4.1.2)
#>  reprex           2.0.2      2022-08-17 [1] CRAN (R 4.1.2)
#>  rlang            1.0.6      2022-09-24 [1] CRAN (R 4.1.2)
#>  rmarkdown        2.18       2022-11-09 [1] CRAN (R 4.1.2)
#>  rstudioapi       0.14       2022-08-22 [1] CRAN (R 4.1.2)
#>  scales           1.2.1      2022-08-20 [1] CRAN (R 4.1.2)
#>  sessioninfo      1.2.2      2021-12-06 [1] RSPM (R 4.1.2)
#>  stringi          1.7.8      2022-07-11 [1] CRAN (R 4.1.2)
#>  stringr          1.5.0      2022-12-02 [1] CRAN (R 4.1.2)
#>  tibble           3.1.8      2022-07-22 [1] CRAN (R 4.1.2)
#>  tidyr            1.2.1      2022-09-08 [1] CRAN (R 4.1.2)
#>  tidyselect       1.2.0      2022-10-10 [1] CRAN (R 4.1.2)
#>  timechange       0.1.1      2022-11-04 [1] CRAN (R 4.1.2)
#>  tsibble          1.1.3      2022-10-09 [1] CRAN (R 4.1.2)
#>  utf8             1.2.2      2021-07-24 [1] RSPM (R 4.1.2)
#>  vctrs            0.5.1      2022-11-16 [1] CRAN (R 4.1.2)
#>  withr            2.5.0      2022-03-03 [1] RSPM (R 4.1.2)
#>  xfun             0.35       2022-11-16 [1] CRAN (R 4.1.2)
#>  yaml             2.3.6      2022-10-18 [1] CRAN (R 4.1.2)
#> 
#>  [1] /home/mitchell/R/x86_64-pc-linux-gnu-library/4.1
#>  [2] /opt/R/4.1.2/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

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