0

Summary

I have a tsibble that I have transformed into a mixed hierarchical (and grouped) time series. For the large majority of specified time series, I can obtain forecasts via the following:

fit <- hg_ts %>%
  fabletools::model(
    stl = fabletools::decomposition_model(
      feasts::STL(log(y), robust = TRUE),
      fable::ETS(season_adjust)))

fit %>%
  fabletools::forecast(h = 4)

For many of the remaining time series, this produces no forecast. In particular, some time series return

Warning: Non-integer lag orders for random walk models are not supported. Rounding to the nearest integer.
...
Warning: 29 errors (1 unique) encountered for stl
[29] The models specified do not combine to give the correct response.
Please check that you have specified the decomposition models appropriately.

Debugging difficulties

If I try debugonce(fabletools::decomposition_model), I see calls to fabletools::new_model_class() and fabletools::new_model_definition(). I took a look at https://fabletools.tidyverts.org/articles/extension_models.html (as well as https://r6.r-lib.org/articles/Debugging.html) but a lot is currently over my head.

How can I reach a "debugging" point (where I can examine all the objects the real code execution knows about) in model_decomposition.R's code where it says

  if(!isTRUE(all.equal(response(model)[[".response"]], .data[[measured_vars(.data)]]))){
    abort(
"The models specified do not combine to give the correct response.
Please check that you have specified the decomposition models appropriately.")
  }

if this were my decomposition model:

library(magrittr)

tsibble::tourism %>%
    fabletools::aggregate_key((State/Region) * Purpose, Trips = sum(Trips)) %>% 
    dplyr::filter(Purpose == "Business", State == "New South Wales") %>% 
    fabletools::model(
        stl = fabletools::decomposition_model(
            feasts::STL(log(Trips), robust = TRUE), 
            fable::ETS(season_adjust)))
#> Warning: 1 error encountered for dcmp
#> [1] promise already under evaluation: recursive default argument reference or earlier problems?
#> Warning: 1 error encountered for stl
#> [1] Problem while computing `cmp = map(.fit, components)`.
#> Loading required namespace: crayon
#> # A mable: 14 x 4
#> # Key:     State, Purpose, Region [14]
#>    State           Purpose  Region                                       stl
#>    <chr*>          <chr*>   <chr*>                                   <model>
#>  1 New South Wales Business Blue Mountains         <STL decomposition model>
#>  2 New South Wales Business Capital Country        <STL decomposition model>
#>  3 New South Wales Business Central Coast                       <NULL model>
#>  4 New South Wales Business Central NSW            <STL decomposition model>
#>  5 New South Wales Business Hunter                 <STL decomposition model>
#>  6 New South Wales Business New England North West <STL decomposition model>
#>  7 New South Wales Business North Coast NSW        <STL decomposition model>
#>  8 New South Wales Business Outback NSW            <STL decomposition model>
#>  9 New South Wales Business Riverina               <STL decomposition model>
#> 10 New South Wales Business Snowy Mountains        <STL decomposition model>
#> 11 New South Wales Business South Coast            <STL decomposition model>
#> 12 New South Wales Business Sydney                 <STL decomposition model>
#> 13 New South Wales Business The Murray             <STL decomposition model>
#> 14 New South Wales Business <aggregated>           <STL decomposition model>

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

For example, I might want to step through code to examine the "error"/"Warning"s, or see why "Central Coast" has a NULL model, etc. Thanks.

josephD
  • 142
  • 7

0 Answers0