Title: | Sparse VAR/VECM Models Estimation |
---|---|
Description: | A wrapper for sparse VAR/VECM time series models estimation using penalties like ENET (Elastic Net), SCAD (Smoothly Clipped Absolute Deviation) and MCP (Minimax Concave Penalty). Based on the work of Sumanta Basu and George Michailidis <doi:10.1214/15-AOS1315>. |
Authors: | Simone Vazzoler [aut, cre] |
Maintainer: | Simone Vazzoler <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0 |
Built: | 2025-02-07 03:26:34 UTC |
Source: | https://github.com/svazzole/sparsevar |
Compute the accuracy of a fit
accuracy(referenceM, A)
accuracy(referenceM, A)
referenceM |
the matrix to use as reference |
A |
the matrix obtained from a fit |
Build the bootstrapped series from the original var
bootstrappedVAR(v)
bootstrappedVAR(v)
v |
the VAR object as from fitVAR or simulateVAR |
A function to find which entries of the impulse response function are zero.
checkImpulseZero(irf)
checkImpulseZero(irf)
irf |
irf output from impulseResponse function |
a matrix containing the indices of the impulse response function that are 0.
Check if the input is a var object
checkIsVar(v)
checkIsVar(v)
v |
the object to test |
Build the VAR(1) representation of a VAR(p) process
companionVAR(v)
companionVAR(v)
v |
the VAR object as from |
This function computes forecasts for a given VAR.
computeForecasts(v, num_steps)
computeForecasts(v, num_steps)
v |
a VAR object as from fitVAR. |
num_steps |
the number of forecasts to produce. |
Creates a sparse square matrix with a given sparsity and distribution.
createSparseMatrix( N, sparsity, method = "normal", stationary = FALSE, p = 1, ... )
createSparseMatrix( N, sparsity, method = "normal", stationary = FALSE, p = 1, ... )
N |
the dimension of the square matrix |
sparsity |
the density of non zero elements |
method |
the method used to generate the entries of the matrix.
Possible values are |
stationary |
should the spectral radius of the matrix be smaller than 1?
Possible values are |
p |
normalization constant (used for VAR of order greater than 1, default = 1) |
... |
other options for the matrix (you can specify the mean
|
An NxN sparse matrix.
M <- createSparseMatrix( N = 30, sparsity = 0.05, method = "normal", stationary = TRUE )
M <- createSparseMatrix( N = 30, sparsity = 0.05, method = "normal", stationary = TRUE )
A function to estimate a (possibly big) multivariate VECM time series using penalized least squares methods, such as ENET, SCAD or MC+.
decomposePi(vecm, rk, ...)
decomposePi(vecm, rk, ...)
vecm |
the VECM object |
rk |
rank |
... |
options for the function (TODO: specify) |
alpha
beta
A function to estimate the confidence intervals for irf and oirf.
errorBandsIRF(v, irf, alpha, M, resampling, ...)
errorBandsIRF(v, irf, alpha, M, resampling, ...)
v |
a var object as from fitVAR or simulateVAR |
irf |
irf output from impulseResponse function |
alpha |
level of confidence (default |
M |
number of bootstrapped series (default |
resampling |
type of resampling: |
... |
some options for the estimation: |
a matrix containing the indices of the impulse response function that are 0.
A function to estimate a (possibly high-dimensional) multivariate VAR time series using penalized least squares methods, such as ENET, SCAD or MC+.
fitVAR(data, p = 1, penalty = "ENET", method = "cv", ...)
fitVAR(data, p = 1, penalty = "ENET", method = "cv", ...)
data |
the data from the time series: variables in columns and observations in rows |
p |
order of the VAR model |
penalty |
the penalty function to use. Possible values
are |
method |
possible values are |
... |
the options for the estimation. Global options are:
|
A
the list (of length p
) of the estimated matrices
of the process
fit
the results of the penalized LS estimation
mse
the mean square error of the cross validation
time
elapsed time for the estimation
residuals
the time series of the residuals
A function to estimate a (possibly high-dimensional) multivariate VARX time series using penalized least squares methods, such as ENET, SCAD or MC+.
fitVARX(data, p = 1, Xt, m = 1, penalty = "ENET", method = "cv", ...)
fitVARX(data, p = 1, Xt, m = 1, penalty = "ENET", method = "cv", ...)
data |
the data from the time series: variables in columns and observations in rows |
p |
order of the VAR model |
Xt |
the exogenous variables |
m |
order of the exogenous variables |
penalty |
the penalty function to use. Possible values are |
method |
possible values are |
... |
the options for the estimation. Global options are:
|
A
the list (of length p
) of the estimated matrices of the process
fit
the results of the penalized LS estimation
mse
the mean square error of the cross validation
time
elapsed time for the estimation
residuals
the time series of the residuals
A function to estimate a (possibly big) multivariate VECM time series using penalized least squares methods, such as ENET, SCAD or MC+.
fitVECM(data, p, penalty, method, logScale, ...)
fitVECM(data, p, penalty, method, logScale, ...)
data |
the data from the time series: variables in columns and observations in rows |
p |
order of the VECM model |
penalty |
the penalty function to use. Possible values are |
method |
|
logScale |
should the function consider the |
... |
options for the function (TODO: specify) |
Pi the matrix Pi
for the VECM model
G the list (of length p-1
) of the estimated matrices of the process
fit the results of the penalized LS estimation
mse the mean square error of the cross validation
time elapsed time for the estimation
Compute the Froebenius norm of M
frobNorm(M)
frobNorm(M)
M |
the matrix (real or complex valued) |
A function to estimate the Impulse Response Function of a given VAR.
impulseResponse(v, len = 20)
impulseResponse(v, len = 20)
v |
the data in the for of a VAR |
len |
length of the impulse response function |
irf
a 3d array containing the impulse response function.
This function computes information criterias (AIC, Schwartz and Hannan-Quinn) for VARs.
informCrit(v)
informCrit(v)
v |
a list of VAR objects as from fitVAR. |
Compute the L1 matrix norm of M
l1norm(M)
l1norm(M)
M |
the matrix (real or complex valued) |
Compute the L2 matrix norm of M
l2norm(M)
l2norm(M)
M |
the matrix (real or complex valued) |
Compute the L-infinity matrix norm of M
lInftyNorm(M)
lInftyNorm(M)
M |
the matrix (real or complex valued) |
Compute the max-norm of M
maxNorm(M)
maxNorm(M)
M |
the matrix (real or complex valued) |
This function generates monte carlo simultaions of sparse VAR and its estimation (at the moment only for VAR(1) processes).
mcSimulations( N, nobs = 250, nMC = 100, rho = 0.5, sparsity = 0.05, penalty = "ENET", covariance = "Toeplitz", method = "normal", modelSel = "cv", ... )
mcSimulations( N, nobs = 250, nMC = 100, rho = 0.5, sparsity = 0.05, penalty = "ENET", covariance = "Toeplitz", method = "normal", modelSel = "cv", ... )
N |
dimension of the multivariate time series. |
nobs |
number of observations to be generated. |
nMC |
number of Monte Carlo simulations. |
rho |
base value for the covariance. |
sparsity |
density of non zero entries of the VAR matrices. |
penalty |
penalty function to use for LS estimation. Possible values are |
covariance |
type of covariance matrix to be used in the generation of the sparse VAR model. |
method |
which type of distribution to use in the generation of the entries of the matrices. |
modelSel |
select which model selection criteria to use ( |
... |
(TODO: complete) |
a nMc
x5 matrix with the results of the Monte Carlo estimation
Multiple plot function. ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
multiplot(..., plotlist = NULL, cols = 1, layout = NULL)
multiplot(..., plotlist = NULL, cols = 1, layout = NULL)
... |
a sequence of ggplots to be plotted in the grid. |
plotlist |
a list containing ggplots as elements. |
cols |
number of columns in layout |
layout |
a matrix specifying the layout. If present, 'cols' is ignored. If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), then plot 1 will go in the upper left, 2 will go in the upper right, and 3 will go all the way across the bottom. Taken from R Cookbook |
A ggplot containing the plots passed as arguments
Plot a IRF object
plotIRF(irf, eb, i, j, type, bands)
plotIRF(irf, eb, i, j, type, bands)
irf |
the irf object to plot |
eb |
the errorbands to plot |
i |
the first index |
j |
the second index |
type |
|
bands |
|
An image
plot relative to the impulse response function.
Plot a IRF grid object
plotIRFGrid(irf, eb, indexes, type, bands)
plotIRFGrid(irf, eb, indexes, type, bands)
irf |
the irf object computed using impulseResponse |
eb |
the error bands estimated using errorBands |
indexes |
a vector containing the indeces that you want to plot |
type |
plot the irf ( |
bands |
which type of bands to plot ("quantiles" (default) or "sd") |
An image
plot relative to the impulse response function.
Plot a sparse matrix
plotMatrix(M, colors)
plotMatrix(M, colors)
M |
the matrix to plot |
colors |
dark or light |
An image
plot with a particular color palette (black zero entries, red
for the negative ones and green for the positive)
Plot all the matrices of a VAR model
plotVAR(..., colors)
plotVAR(..., colors)
... |
a sequence of VAR objects (one or more
than one, as from |
colors |
the gradient used to plot the matrix. It can be "light" (low = red – mid = white – high = blue) or "dark" (low = red – mid = black – high = green) |
An image
plot with a specific color palette
Plot all the matrices of a VECM model
plotVECM(v)
plotVECM(v)
v |
a VECM object (as from |
An image
plot with a specific color palette (black zero entries, red
for the negative ones and green for the positive)
This function generates a simulated multivariate VAR time series.
simulateVAR(N, p, nobs, rho, sparsity, mu, method, covariance, ...)
simulateVAR(N, p, nobs, rho, sparsity, mu, method, covariance, ...)
N |
dimension of the time series. |
p |
number of lags of the VAR model. |
nobs |
number of observations to be generated. |
rho |
base value for the covariance matrix. |
sparsity |
density (in percentage) of the number of nonzero elements of the VAR matrices. |
mu |
a vector containing the mean of the simulated process. |
method |
which method to use to generate the VAR matrix. Possible values
are |
covariance |
type of covariance matrix to use in the simulation. Possible
values: |
... |
the options for the simulation. These are:
|
A a list of NxN matrices ordered by lag
data a list with two elements: series
the multivariate time series and
noises
the time series of errors
S the variance/covariance matrix of the process
This function generates a simulated multivariate VAR time series.
simulateVARX(N, K, p, m, nobs, rho, sparsityA1, sparsityA2, sparsityA3, mu, method, covariance, ...)
simulateVARX(N, K, p, m, nobs, rho, sparsityA1, sparsityA2, sparsityA3, mu, method, covariance, ...)
N |
dimension of the time series. |
K |
TODO |
p |
number of lags of the VAR model. |
m |
TODO |
nobs |
number of observations to be generated. |
rho |
base value for the covariance matrix. |
sparsityA1 |
density (in percentage) of the number of nonzero elements of the A1 block. |
sparsityA2 |
density (in percentage) of the number of nonzero elements of the A2 block. |
sparsityA3 |
density (in percentage) of the number of nonzero elements of the A3 block. |
mu |
a vector containing the mean of the simulated process. |
method |
which method to use to generate the VAR matrix. Possible values
are |
covariance |
type of covariance matrix to use in the simulation. Possible
values: |
... |
the options for the simulation. These are:
|
A a list of NxN matrices ordered by lag
data a list with two elements: series
the multivariate time series and
noises
the time series of errors
S the variance/covariance matrix of the process
It performs the estimation of the matrices of the models using penalized least squares methods such as LASSO, SCAD and MCP.
fitVAR
, fitVECM
, simulateVAR
, createSparseMatrix
,
plotMatrix
, plotVAR
, plotVECM
l2norm
, l1norm
, lInftyNorm
, maxNorm
, frobNorm
,
spectralRadius
, spectralNorm
, impulseResponse
Compute the spectral norm of M
spectralNorm(M)
spectralNorm(M)
M |
the matrix (real or complex valued) |
Compute the spectral radius of M
spectralRadius(M)
spectralRadius(M)
M |
the matrix (real or complex valued) |
This function should retain only the coefficients of the matrices of the VAR that are statistically significative (from the bootstrap)
testGranger(v, eb)
testGranger(v, eb)
v |
the VAR object as from fitVAR or simulateVAR |
eb |
the error bands as obtained from errorBands |
Transform the input data
transformData(data, p, opt)
transformData(data, p, opt)
data |
the data |
p |
the order of the VAR |
opt |
a list containing the options |
Estimate VAR using ENET penalty
varENET(data, p, lambdas, opt)
varENET(data, p, lambdas, opt)
data |
the data |
p |
the order of the VAR |
lambdas |
a vector containing the lambdas to be used in the fit |
opt |
a list containing the options |
Estimate VAR using MCP penalty
varMCP(data, p, lambdas, opt)
varMCP(data, p, lambdas, opt)
data |
the data |
p |
the order of the VAR |
lambdas |
a vector containing the lambdas to be used in the fit |
opt |
a list containing the options |
Estimate VAR using SCAD penalty
varSCAD(data, p, lambdas, opt, penalty)
varSCAD(data, p, lambdas, opt, penalty)
data |
the data |
p |
the order of the VAR |
lambdas |
a vector containing the lambdas to be used in the fit |
opt |
a list containing the options |
penalty |
a string "SCAD" or something else |