business-science / modeltime

Modeltime unlocks time series forecast models and machine learning in one framework
https://business-science.github.io/modeltime/
Other
515 stars 78 forks source link

Time Series - Multiple regression (VAR, Vector Autoregression) #77

Open coforfe opened 3 years ago

coforfe commented 3 years ago

Hi Matt,

First of all, thanks for all you are doing around modeltime. It's clearly a big step forward for TimeSeries modeling.

Perhaps it is already covered but I am not able to see if in modeltime is considered the case where you can put several time series together. Define one of them as a target and check how influencial are the rest (as predictors). What I have seen so far is how to model a univariant time series, by extracting different features and model it.

Thanks again, Carlos Ortega.

mdancho84 commented 3 years ago

Hey @coforfe , Thanks for this. I'll add VAR to the roadmap. Just not completely sure what your needs are.

The core idea for modeltime is to allow the user to add regressors and developed scalable forecast models using any algorithm.

The VAR data format is, in its most basic form, just a regression. So you can do regression in modeltime already. For the VAR problem, just:

  1. Make a tibble() with each of your series
  2. Specify a target and predictors in a recipe.
  3. Model.
  4. Use the modeltime workflow to visualize the results.

The only thing I can think of possibly adding helpers around formatting the data as a VAR problem.

Also maybe adding feature importance tools down the road.

I'm interested to hear more of what your needs are so I can understand if I am on the right track.

References

Vector Autoregressions - Econometrics with R.

coforfe commented 3 years ago

Hi Matt,

Thanks. Well quite frankly I was not aware that already with modeltime it was possible to model a time series using another ones as predictors. I do not remember seeing an example of this in the vignettes or in the Youtube (the ones you did with Max and with Josh). If it is already available in your "Labs Pro", I will subscribe for that.

Thanks again, Carlos.

mdancho84 commented 3 years ago

Yes, modeltime is designed for many features including using other time series as predictors. The challenge is that you need to know predict using the lags of the other series. We can now do this with recursive(), which is being actively worked on currently. Learning Labs PRO will have a full demonstration once it's ready.

Regarding learning more, here's where to go for topics.

Time Series Forecasting Course

The High-Performance Time Series Course teaches the main elements of the ecosystem in incredible depth.

image

Learning Labs PRO - Special Time Series Topics

We have a special time series section of labs that address special topics in Modeltime like panel forecasting, recursive() for a forecasting with lags, etc. We have more coming including the new additions such as modeltime.h2o and panel recursion.

image

coforfe commented 3 years ago

OK. Matt. Thanks a lot for your clear references and I will forward to seeing this new functionality available in modeltime. Thanks again, Carlos.

AlbertoAlmuinha commented 3 years ago

I think VAR can be implemented through recursive() function using lags as the transformation function, basically what we are doing is taking the previous lags of the xregs to fulfill the NA values and forecast.

Maybe we could explain the relation between recursive and VAR models to be more concise.

Regards,

mdancho84 commented 3 years ago

Yes, this is probably a Learning Lab where students can learn how to do this. We'll have learning labs on topics like:

GitHunter0 commented 3 years ago

A fundamental method that is used a lot in Finance and Economics and generalizes VAR (vector autoregressive) is VECM (vector error-correction models).

Do you plan to incorporate it too? I believe it would be an important addition to modeltime.

As reference, you may check Stata's documentation (hyperlinks above) and Python's statsmodels

Thank you

mdancho84 commented 3 years ago

@GitHunter0 Thanks for this. VAR was added to the roadmap some time ago so we have on our radar. May take a bit but will try to get in soon.

For most up to date roadmap check out issue #5.

GitHunter0 commented 3 years ago

Thank you @mdancho84 , I know you are pretty busy right now, doing great work as always.

PS: A good thing about VECM methodology is that not only you can specify the system of equations (like VAR) but it can also handle non-stationary series. It is a well established method to forecast multiple time series that depend on each other and probably should be the baseline to test the performance of the new deep learning methods.

mdancho84 commented 3 years ago

@GitHunter0 Is there a preferred implementation in R?

spsanderson commented 3 years ago

@mdancho84 maybe this link will give some light:

https://www.r-econometrics.com/timeseries/vecintro/

GitHunter0 commented 3 years ago

@mdancho84 , unfortunately I believe there are very few options of packages that handle VEC models in R, tsDyn must be the main/best one (although its focus is on more advanced (nonlinear) VAR/VEC versions). I couldn't find an R package that comes close to Stata's professional quality, clear API and well documented implementation (however it is a paid software). Therefore, I have very little experience working with VEC and VAR models in R, which is a shame since it opens up much more possibilities than Stata. timetk and modeltime are game changers in that regard, providing a unified and well designed system to work with time series. The more packages like yours evolve, the more users will be able to break free from proprietary software and take advantage of the fantastic capabilities that R offers.

vidarsumo commented 2 years ago

For VAR and VECM I would go for the vars package in R (https://cran.r-project.org/web/packages/vars/vignettes/vars.pdf). I've only used VAR/VECM to analyze impulse response functions. For forecasting I would always go for other methods, something that is already available in modeltime.

What I'm excited for is GPVAR (https://ts.gluon.ai/api/gluonts/gluonts.model.gpvar.html) which, if I understand it fully, allows you to model thousands of time series that are functions of each other. Something I think VAR would struggle with.

mdancho84 commented 2 years ago

The GPVAR might not be that bad. I'll have to take a look.

Shafi2016 commented 2 years ago

Hi, @mdancho84 It would be good to add DeepVAR(https://ts.gluon.ai/api/gluonts/gluonts.model.deepvar.html) . DeepVAR estimator, which is a multivariate variant of DeepAR. I think this will solve our Xreg problem in DeepAR as most of us are interested in it.