Learn R Programming

⚠️There's a newer version (1.0.0) of this package.Take me there.

Sparse VAR (sparsevar)

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 matrices

plotComparisonVAR(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+;
  • 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;
  • 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;
  • plotComparisonVAR: plot the comparison between the matrices of the simulated model and the matrices of the estimate.
  • plotIRF: plot IRF function;
  • plotGridIRF: multiple plots of IRF.

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.

Copy Link

Version

Install

install.packages('sparsevar')

Monthly Downloads

36

Version

0.0.9

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Simone Vazzoler

Last Published

October 19th, 2016

Functions in sparsevar (0.0.9)

errorBandsIRF

Error bands for IRF
bootstrappedVAR

Bootstrap VAR
companionVAR

Companion VAR
fitVECM

Multivariate VECM estimation
frobNorm

Froebenius norm of a matrix
impulseResponse

Impulse Response Function
mcSimulations

Monte Carlo simulations
maxNorm

Max-norm of a matrix
lInftyNorm

L-infinity matrix norm
l2norm

L2 matrix norm
checkImpulseZero

Check Impulse Zero
varENET

VAR ENET
plotIRF

IRF plot
plotComparisonVAR

Plot VAR models for comparison
plotVAR

VAR plot
l1norm

L1 matrix norm
informCrit

Computes information criteria for VARs
testGranger

Test for Ganger Causality
sparsevar

sparsevar: A package to estimate multivariate time series models (such as VAR and VECM), under the sparsity hypothesis.
simulateVAR

VAR simulation
transformData

Transorm data
spectralRadius

Spectral radius
plotIRFGrid

IRF grid plot
varSCAD

VAR SCAD
plotMatrix

Matrix plot
varMCP

VAR MCP
spectralNorm

Spectral norm
accuracy

Accuracy metric
createSparseMatrix

Create Sparse Matrix
computeForecasts

Computes forecasts for VARs
checkIsVar

Check is var
fitVAR

Multivariate VAR estimation