0

I have generated a forecast with the tree-based method and now want to create a fable object. Therefore I created a tsibble object "fc_cart" (details at the end) with the predicted values (yhat) and bootstrapped residuals for the prediction intervals (boot).

I use the following statement to create the fable object:

fable_cart <- as_fable(fc_cart, response="yhat", distribution="boot")

And get the error:


Error in dimnames(fbl[[distribution]]) <- response : 
  'dimnames' applied to non-array
In addition: Warning message:
The dimnames of the fable's distribution are missing and have been set to match the response variables. 

I have no idea what this mean.... Would be very grateful for any help!

> print(fc_cart,n=2)
# A tsibble: 365 x 3 [1D]
  date        yhat boot          
  <date>     <dbl> <list>        
1 2022-01-01  121. <dst_smpl[1d]>
2 2022-01-02  121. <dst_smpl[1d]>
# ℹ 363 more rows

The column boot was created with (to keep the snippet short here with rnorm; in my real implementation it is a bootstrap on the training residuals):

for (i in 1:nrow(fc_cart)) {
  my_dist <- distributional::dist_sample(
    list(
      rnorm(1000)
    )
  )
  fc_cart$boot[i] <- my_dist
} 
Mat
  • 1
  • 3
  • The distribution variable `boot` needs to be a distribution from the {distributional} package. If you only have point forecasts, you may like to use `dist_degenerate()`. – Mitchell O'Hara-Wild Jun 10 '23 at 16:26
  • thank you very much for your help. Now I use dist_generate() and have updated/enhanced the Question. I get the same error message. Maybe the last code snippet, which creates the column boot is the problem? – Mat Jun 10 '23 at 17:46
  • Please look at the examples of degenerate distributions here: https://pkg.mitchelloharawild.com/distributional/reference/dist_degenerate.html If you have a sample of 1000 numbers for each forecast, you would need to use dist_sample() instead. – Mitchell O'Hara-Wild Jun 11 '23 at 03:10
  • @Mitchell O'Hara-Wild: thank you very much for your very helpful infos again. As a newcomer I understand the great thing fable better now and have corrected the code above. Unfortunately I get the same error message. It would be great, if you can give me a hint again. In the meantime I use a workaround: I append my tsibble object fc_cart to an existing fable object via bind_rows() and so I can use things like accuracy(), auoplot and so on. – Mat Jun 11 '23 at 16:55
  • You've got a list of distributions, rather than a vector of distributions. Try `fc_cart$boot <- distributional::dist_sample(lapply(1:nrow(fc_cart), function(...) rnorm(1000)))` – Mitchell O'Hara-Wild Jun 12 '23 at 00:48
  • @Mitchell O'Hara-Wild: Great; that works :-) many thanks for the very helpful and fast support – Mat Jun 12 '23 at 16:08

1 Answers1

0
fc_cart$boot <- distributional::dist_sample(lapply(1:nrow(fc_cart), function(...) rnorm(1000)))
Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
Mat
  • 1
  • 3