Code Monkey home page Code Monkey logo

sparsevar's Introduction

Sparse VAR (sparsevar)

License Version CRAN_Status_Badge Downloads Total Downloads Build Status

Some R functions useful to estimate sparse VAR / VECM models.

Installation

To install the stable version from CRAN:

install.package("sparsevar")

To install the developing version:

install.packages("devtools")
devtools::install_github("svazzole/sparsevar", "master")

Check here to understand which are the dependencies of devtools for your OS.

Quick start

To load the sparsevar package simply type

library(sparsevar)

Using the function included in the package, we simply generate a 20x20 VAR(2) process

set.seed(1)
sim <- simulateVAR(N = 20, p = 2)

This command will generate a model with two sparse matrices with 5% of non-zero entries and a Toeplitz variance-covariance matrix with rho = 0.5. We can estimate the matrices of the process using for example

fit <- fitVAR(sim$series, p = 2, threshold = TRUE)

The results can be seen by plotting the two var objects

plotVAR(sim, fit)

the first row of the plot is made by the matrices of the simulated process and the second row is formed by their estimates.

The fit contains also the estimate of the variance/covariance matrix of the residuals

plotMatrix(fit$sigma)

which can be compared with the covariance matrix of the errors of the generating process

plotMatrix(sim$sigma)

Usage

The functions included for model estimation are:

  • fitVAR: to estimate a sparse VAR multivariate time series with ENET, SCAD or MC+;
  • fitVARX: to estimate a sparse VAR-X model using ENET;
  • fitVECM: to estimate a sparse VECM (Vector Error Correction Model) using LS with penalty (again: ENET, SCAD or MC+);
  • impulseResponse: compute the impulse response function;
  • errorBands: estimate the error bands for the IRF (using bootstrap).

For simulations:

  • simulateVAR: to generate a sparse VAR multivariate time series;
  • simulateVARX: to generate a sparse VARX time series;
  • createSparseMatrix: used to create sparse matrices with a given density.

For plotting:

  • plotMatrix: useful to plot matrices and sparse matrices;
  • plotVAR: plot all the matrices of the model or models in input;
  • plotIRF: plot IRF function;
  • plotGridIRF: multiple plots of IRF.

Papers using sparsevar

[1] Gibbons SM, Kearney SM, Smillie CS, Alm EJ (2017) Two dynamic regimes in the human gut microbiome. PLoS Comput Biol 13(2): e1005364.

[2] Quentin Guibert, Olivier Lopez, Pierrick Piette, Forecasting mortality rate improvements with a high-dimensional VAR, Insurance: Mathematics and Economics, Volume 88, 2019, Pages 255-272, ISSN 0167-6687.

References

[1] Basu, Sumanta; Michailidis, George. Regularized estimation in sparse high-dimensional time series models. Ann. Statist. 43 (2015), no. 4, 1535--1567. doi:10.1214/15-AOS1315.

[2] Lütkepohl, Helmut. New Introduction to Multiple Time Series Analysis. Springer Science & Business Media, 2005, ISBN 3540277528.

sparsevar's People

Contributors

pierrickpiette avatar svazzole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sparsevar's Issues

Adding exogenous inputs

Hi,

Is there any way to fit a sparse autoregressive with exogenous inputs using Sparsevar package?

I could not find anything about it in the help.

Thank you

Cross Validation problem

Hi,

In the function 'fitVAR', 'cv.glmnet' and 'cv.ncvreg' use k-fold cross validation. I think this is not appropriate for time series data, since the time for the (k-1) training folds are not continuous any more. Is there any way to use validation set approach in 'fitVAR'?

Hope I 've made my point clear. Thank you for reading!

VECM forecasts, documentation and bug fix.

Thanks for the package! I would like to generate forecasts from sparse VECM's. Could you add a function to do this? In the meanwhile could you let me know how to do it? It would be great if you could update the documentation insofar as making it clear what the underlying models and the matrices in the output are, e.g. what are the Pi and G matrices? Also How do you determine the order of cointegration? (Johannsen?). There also seem to be some bugs in the code. For example I did not manage to run computeForecasts(spVAR, numSteps = 1), where spVAR is a VAR of lag-order p = 3. I believe the error is found in the following line of computeForecasts:

    tmpData <- matrix(data = t(data[(nr - p + 1):nr, ]), 
      nrow = nc, ncol = numSteps)

Setting numSteps = 1 here removes two columns from the data. That line should read:

    tmpData <- matrix(data = t(data[(nr - p + 1):nr, ]), 
      nrow = nc, ncol = p)

I presume you are no longer actively developing this package, but it still seems the only package to estimate sparse VECM's - so it would be great to have a functional toolset for that. Possibly you could also use the function vec2var from the vars package to convert the sparse VECM to a level VAR representation and enable the use of he methods of the vars package on it.

Manual choice of lambda

Hi,

in using the fitVAR function, is there the possibility to manually give a value for lambda rather than using 'cv' or 'timeSlice' methods to find lambda?
Would like to test ENET regularization on my data for different lambdas but could not find anything which enables me to do so.

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.