robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.11k stars 341 forks source link

tsCV function is not working when xreg is provided #864

Closed john-grando closed 2 years ago

john-grando commented 3 years ago

When using the xreg option in the tsCV() function I encountered a few issues and decided to look into them. I prepared a report summarizing the findings and proposed fixes for this function. Thank you so much for providing this great resource. Please let me know if you would like a pull request provided. I wasn't sure how you had this project set up and didn't want to just push something without checking.

Report Edited tsCV file

robjhyndman commented 3 years ago

Thanks for bringing this to my attention. I've implemented a simpler fix in https://github.com/robjhyndman/forecast/commit/9c79dc3f16242c60944d5c90cbcd15fa631538a1. Please test it and let me know if it is now working. I've added an example to help(tsCV) to show how to implement a function with an xreg argument.

As this package is now in "retired" mode, we are not adding new functionality -- just fixing any bugs that arise and keeping it maintained as required.

tamas-ferenci commented 3 years ago

Dear @robjhyndman , is/will tsCV be included in fable...?

mitchelloharawild commented 3 years ago

Dear @robjhyndman , is/will tsCV be included in fable...?

Refer to this resource for how cross-validation can be done in {fable}: https://otexts.com/fpp3/tscv.html

Some discussion on potential improved/alternative interfaces for cross-validation is here: https://github.com/tidyverts/fabletools/issues/180

tamas-ferenci commented 3 years ago

Thank @mitchelloharawild for the extremely prompt reply!

As a sidenote, I think parameter h is not passed to the function in the far2_xreg example of the manual.

mitchelloharawild commented 3 years ago

As a sidenote, I think parameter h is not passed to the function in the far2_xreg example of the manual.

I'm not sure which example you're referring to, could you provide a link to this?

tamas-ferenci commented 3 years ago

https://github.com/robjhyndman/forecast/blob/d6ebe534f802d9cbcae9d4eb0717fb83217d537d/R/tscv.R#L52

The function has a parameter h, but it is never used within the function.

mitchelloharawild commented 3 years ago

The forecast.Arima() horizon h is taken to be the number of rows in newxreg, which is produced in tsCV to have h rows. You could pass in h also, but it would be overwritten by nrow(newxreg).

To add to this, the h parameter is required as it needed by tsCV.

tamas-ferenci commented 3 years ago

I see, thank you very much!

mitchelloharawild commented 2 years ago

Closing as this is fixed. The {forecast} package is retired, and this is also possible to be done in {fable}.