promise already under evaluation: recursive default argument reference or earlier problems?

Dear all, I'm facing the problem promise already under evaluation in a context that I fail to see any function call. I'm following the first sample code of the page

of the great book Forecasting Principles and Practice.

I'm using a tsibble very similar to the one in the book, only that it hasn't a key, just an index.

If I eliminate the 1st two lines of the code, that filter its tsibble, the same promise already under evaluation: recursive default argument reference or earlier problems? error will arise.

However, the original tsibble and the filtered one seem to have the same structure.

All I would like to do is to decompose my time series in its several components.

I'm very new to the tidyverse, and it would be nice to use its impressive power.

Which code? This?

library(fpp3)

us_retail_employment <- us_employment %>%
  filter(year(Month) >= 1990, Title == "Retail Trade")

dcmp <- us_retail_employment %>%
  model(STL(Employed ~ trend(window = 7), robust = TRUE)) %>%
  components() %>%
  select(-.model)

dcmp %>%
  model(NAIVE(season_adjust)) %>%
  forecast() %>%
  autoplot(dcmp) +
  labs(y = "Number of people",
       title = "US retail employment")

Perhaps you could provide a reproducibe example?

Thanks for your prompt answer. There's a fine line between writing too much (and receiving TL;DR) and writing too little. I probably stayed in the latter alternative.

Please consider the fragment

library(fpp3)

dcmp <- us_employment %>%
  model(STL(Employed ~ trend(window = 7), robust = TRUE)) %>%
  components() %>%
  select(-.model)

dcmp %>%
  model(NAIVE(season_adjust)) %>%
  forecast() %>%
  autoplot(dcmp) +
  labs(y = "Number of people",
       title = "US retail employment")

It generates the same error

[126] promise already under evaluation: recursive default argument reference or earlier problems?

I think that this qualifies for a minimal reproducible fragment, and it is -- as I told before -- the original sample code without the filter() part.

My own code has this and more, but I will try to comment that as soon as I have a clearer view of its behavior.

1 Like

How are you intending to account for us_employment being a collection of series ?
are you looking to ignore the collection and treat as one single series , or would you want to repeat the model fitting for each series ?
if the former I would look to alter the data so as to homogenise it, the latter I would purrr::map over it.

1 Like

Agreed, @nirgrahamuk !

Indeed us_employment has data for several different contexts, or time series. The purpose of the filter for Title is to select the time series of employment for Retail Trade.

May I suppose that the promise under evaluation mentioned in the error is related to the need to select one of those series ?

In my own example I don't have such grouping of series in my tsibble. In my original tsibble I don't even have a key, just the necessary index, that's Date_Time, a dttm column.

That's the original tsibble

# A tsibble: 336 x 9 [1h] <UTC>
        Millisec Date       Time      Price    Market.Cap Total.Volume  Diff Category Date_Time          
           <dbl> <chr>      <chr>     <dbl>         <dbl>        <dbl> <dbl>    <int> <dttm>             
 1 1648036843518 2022-03-23 12:00:00 42016. 796930221483. 20648703196.     0        1 2022-03-23 12:00:00
 2 1648040442434 2022-03-23 13:00:00 42338. 804073030049. 20926236402.  3598        1 2022-03-23 13:00:00
 3 1648044139399 2022-03-23 14:00:00 42065. 798875221477. 21118078925.  3697        1 2022-03-23 14:00:00
 4 1648047861682 2022-03-23 15:00:00 42321. 802527669477. 20733550893.  3723        1 2022-03-23 15:00:00
 5 1648051386829 2022-03-23 16:00:00 42650. 810581716573. 21410112661.  3525        1 2022-03-23 16:00:00
 6 1648054905172 2022-03-23 17:00:00 42554. 807780574540. 21599467949.  3518        1 2022-03-23 17:00:00
 7 1648058638449 2022-03-23 18:00:00 42105. 803114313672. 21677210160.  3733        1 2022-03-23 18:00:00
 8 1648062179542 2022-03-23 19:00:00 42141. 800978301718. 21907110841.  3542        1 2022-03-23 19:00:00
 9 1648065844756 2022-03-23 20:00:00 42256. 803357179362. 22142038526.  3665        1 2022-03-23 20:00:00
10 1648069275246 2022-03-23 21:00:00 42333. 803979986190. 21813041714.  3430        1 2022-03-23 21:00:00
# … with 326 more rows

That's what caused the promise already under evaluation error in the FPP sample code. If I use any variable except Category to filter the data, the error won't happen. For instance, as in the fragment

my_data <- as_tsibble(ts_data, key = Millisec, index = Date_Time)

my_data <- my_data %>%
  filter(Millisec >= 1)

That will create another tsibble like

# A tsibble: 336 x 9 [1h] <UTC>
# Key:       Millisec [336]
        Millisec Date       Time      Price    Market.Cap Total.Volume  Diff Category Date_Time          
           <dbl> <chr>      <chr>     <dbl>         <dbl>        <dbl> <dbl>    <int> <dttm>             
 1 1648036843518 2022-03-23 12:00:00 42016. 796930221483. 20648703196.     0        1 2022-03-23 12:00:00
 2 1648040442434 2022-03-23 13:00:00 42338. 804073030049. 20926236402.  3598        1 2022-03-23 13:00:00
 3 1648044139399 2022-03-23 14:00:00 42065. 798875221477. 21118078925.  3697        1 2022-03-23 14:00:00
 4 1648047861682 2022-03-23 15:00:00 42321. 802527669477. 20733550893.  3723        1 2022-03-23 15:00:00
 5 1648051386829 2022-03-23 16:00:00 42650. 810581716573. 21410112661.  3525        1 2022-03-23 16:00:00
 6 1648054905172 2022-03-23 17:00:00 42554. 807780574540. 21599467949.  3518        1 2022-03-23 17:00:00
 7 1648058638449 2022-03-23 18:00:00 42105. 803114313672. 21677210160.  3733        1 2022-03-23 18:00:00
 8 1648062179542 2022-03-23 19:00:00 42141. 800978301718. 21907110841.  3542        1 2022-03-23 19:00:00
 9 1648065844756 2022-03-23 20:00:00 42256. 803357179362. 22142038526.  3665        1 2022-03-23 20:00:00
10 1648069275246 2022-03-23 21:00:00 42333. 803979986190. 21813041714.  3430        1 2022-03-23 21:00:00
# … with 326 more rows

But of course, that makes no sense, for no variable besides Category is really a grouping variable. And indeed Category is a fake variable, used to create a fake group that would include all the data. Unfortunately, using Category as is will cause the same promise already under the evaluation error.

Maybe it's because there's a single value for Category, and it's 1.

The shameless hack that I'm considering to use will be to add fake data, and fake values for the fake variable Category, with values differ from 1, just to have a meaningful grouping, just like in the original FPP data.

As already pointed out, us_employment contains a large number of time series, and you are computing an STL decomposition on each one. The error suggests that there is a problem with doing that for at least one series.

So let's check the individual STL models.

library(fpp3)

us_employment %>%
  model(STL(Employed ~ trend(window = 7), robust = TRUE))
#> Warning: 126 errors (1 unique) encountered for STL(Employed ~ trend(window = 7), robust = TRUE)
#> [126] promise already under evaluation: recursive default argument reference or earlier problems?
#> # A mable: 148 x 2
#> # Key:     Series_ID [148]
#>    Series_ID     `STL(Employed ~ trend(window = 7), robust = TRUE)`
#>    <chr>                                                    <model>
#>  1 CEU0500000001                                              <STL>
#>  2 CEU0600000001                                              <STL>
#>  3 CEU0800000001                                              <STL>
#>  4 CEU1000000001                                              <STL>
#>  5 CEU1011330001                                       <NULL model>
#>  6 CEU1021000001                                       <NULL model>
#>  7 CEU1021100001                                       <NULL model>
#>  8 CEU1021200001                                       <NULL model>
#>  9 CEU1021210001                                       <NULL model>
#> 10 CEU1021300001                                       <NULL model>
#> # … with 138 more rows

Created on 2022-04-21 by the reprex package (v2.0.1)

The first four models look ok, but then there are several that are NULL indicating the modelling failed for some reason.

So let's look at one of those series.

us_employment %>% filter(Series_ID == "CEU1021000001")
#> # A tsibble: 969 x 4 [1M]
#> # Key:       Series_ID [1]
#>       Month Series_ID     Title                      Employed
#>       <mth> <chr>         <chr>                         <dbl>
#>  1 1939 Jan CEU1021000001 Mining and Logging: Mining       NA
#>  2 1939 Feb CEU1021000001 Mining and Logging: Mining       NA
#>  3 1939 Mar CEU1021000001 Mining and Logging: Mining       NA
#>  4 1939 Apr CEU1021000001 Mining and Logging: Mining       NA
#>  5 1939 May CEU1021000001 Mining and Logging: Mining       NA
#>  6 1939 Jun CEU1021000001 Mining and Logging: Mining       NA
#>  7 1939 Jul CEU1021000001 Mining and Logging: Mining       NA
#>  8 1939 Aug CEU1021000001 Mining and Logging: Mining       NA
#>  9 1939 Sep CEU1021000001 Mining and Logging: Mining       NA
#> 10 1939 Oct CEU1021000001 Mining and Logging: Mining       NA
#> # … with 959 more rows

Created on 2022-04-21 by the reprex package (v2.0.1)

That's a lot of missing values and STL can't handle missing values. So there's the problem. Either estimate the missing values, or try fitting to the parts of the series that are complete.

Let's find the first and last non-missing observations.

us_employment %>%
  as_tibble() %>%
  group_by(Month) %>%
  summarise(Employed = sum(Employed)) %>%
  filter(!is.na(Employed)) %>%
  filter(Month == min(Month) | Month == max(Month))
#> # A tibble: 2 × 2
#>      Month Employed
#>      <mth>    <dbl>
#> 1 2001 Jan  759781.
#> 2 2017 Dec  868382.

Created on 2022-04-21 by the reprex package (v2.0.1)

So the first month where all data is available is January 2001, and the last is Dec 2017. So we can try applying STL on the data between those dates.

us_employment %>%
  filter(year(Month) >= 2001 & year(Month) <= 2017) %>%
  model(STL(Employed ~ trend(window = 7), robust = TRUE)) %>%
  components() %>%
  select(-.model)
#> # A tsibble: 30,192 x 7 [1M]
#> # Key:       Series_ID [148]
#>    Series_ID        Month Employed   trend season_year remainder season_adjust
#>    <chr>            <mth>    <dbl>   <dbl>       <dbl>     <dbl>         <dbl>
#>  1 CEU0500000001 2001 Jan   109928 112128.      -1961. -2.39e+ 2       111889.
#>  2 CEU0500000001 2001 Feb   110140 111927.      -1771. -1.57e+ 1       111911.
#>  3 CEU0500000001 2001 Mar   110603 111725.      -1180.  5.82e+ 1       111783.
#>  4 CEU0500000001 2001 Apr   110962 111528.       -459. -1.07e+ 2       111421.
#>  5 CEU0500000001 2001 May   111624 111335.        313. -2.40e+ 1       111311.
#>  6 CEU0500000001 2001 Jun   112303 111161.       1118.  2.36e+ 1       111185.
#>  7 CEU0500000001 2001 Jul   111897 110999.        905. -7.74e+ 0       110992.
#>  8 CEU0500000001 2001 Aug   111827 110716.        907.  2.03e+ 2       110920.
#>  9 CEU0500000001 2001 Sep   111086 110460.        443.  1.84e+ 2       110643.
#> 10 CEU0500000001 2001 Oct   110771 110194.        577. -2.91e-11       110194.
#> # … with 30,182 more rows

Created on 2022-04-21 by the reprex package (v2.0.1)

Now everything works.

Because there are 148 series here, your attempted plot will show 148 facetted plots of forecasts, which is probably not what you want.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.