Title: | State-Dependent Empirical Analysis |
---|---|
Description: | A set of tools for state-dependent empirical analysis through both VAR- and local projection-based state-dependent forecasts, impulse response functions, historical decompositions, and forecast error variance decompositions. |
Authors: | Tyler J. Pike [aut, cre] |
Maintainer: | Tyler J. Pike <[email protected]> |
License: | GPL-3 |
Version: | 1.2.1 |
Built: | 2024-11-26 04:23:36 UTC |
Source: | https://github.com/tylerjpike/sovereign |
Implement the deterministic volatility correction method of Lenza, Michele and Giorgio Primiceri "How to Estimate a VAR after March 2020" (2020) [NBER Working Paper]. Correction factors are estimated via maximum likelihood.
covid_volatility_correction(var, theta_initial = c(5, 2, 1.5, 0.8))
covid_volatility_correction(var, theta_initial = c(5, 2, 1.5, 0.8))
var |
VAR object |
theta_initial |
double: four element vector with scaling parameters, theta in Lenza and Primiceri (2020) |
var object
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2018-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # correct VAR for COVID shock var = sovereign::covid_volatility_correction(var) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2018-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # correct VAR for COVID shock var = sovereign::covid_volatility_correction(var) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
Estimate the forecast error variance decomposition for VARs with either short or 'IV-short' structural errors. See VAR and RVAR documentation for details regarding structural errors.
FEVD(model, horizon = 10, scale = TRUE)
FEVD(model, horizon = 10, scale = TRUE)
model |
VAR or RVAR class object |
horizon |
int: number of periods |
scale |
boolean: scale variable contribution as percent of total error |
long-form data.frame
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::IRF(var) # forecast error variance decomposition var.fevd = sovereign::FEVD(var) # historical shock decomposition var.hd = sovereign::HD(var)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::IRF(var) # forecast error variance decomposition var.fevd = sovereign::FEVD(var) # historical shock decomposition var.hd = sovereign::HD(var)
Estimate the historical decomposition for VARs with either 'short' or 'IV-short' structural errors. See VAR and RVAR documentation for details regarding structural errors.
HD(model)
HD(model)
model |
VAR or RVAR class object |
long-from data.frame
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::IRF(var) # forecast error variance decomposition var.fevd = sovereign::FEVD(var) # historical shock decomposition var.hd = sovereign::HD(var)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::IRF(var) # forecast error variance decomposition var.fevd = sovereign::FEVD(var) # historical shock decomposition var.hd = sovereign::HD(var)
See VAR, RVAR, LP, and RLP documentation for details regarding models and structural errors.
IRF( model, horizon = 10, CI = c(0.1, 0.9), bootstrap.type = "auto", bootstrap.num = 100, bootstrap.parallel = FALSE, bootstrap.cores = -1 )
IRF( model, horizon = 10, CI = c(0.1, 0.9), bootstrap.type = "auto", bootstrap.num = 100, bootstrap.parallel = FALSE, bootstrap.cores = -1 )
model |
VAR, RVAR, LP, or RLP class object |
horizon |
int: number of periods |
CI |
numeric vector: c(lower ci bound, upper ci bound) |
bootstrap.type |
string: bootstrapping technique to use ('auto', 'standard', or 'wild'); if auto then wild is used for IV or IV-short, else standard is used |
bootstrap.num |
int: number of bootstraps |
bootstrap.parallel |
boolean: create IRF draws in parallel |
bootstrap.cores |
int: number of cores to use in parallel processing; -1 detects and uses half the available cores |
data frame with columns target
, shock
, horizon
, response.lower
, response
, response.upper
; regime-based models return a list with a data frame per regime.
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4 ) # impulse response function var.irf = sovereign::IRF(var) # local projection forecasts lp = sovereign::LP( data = Data, horizon = c(1:10), lag.ic = 'AIC', lag.max = 4, type = 'both', freq = 'month') # LP impulse response function lp.irf = sovereign::IRF(lp)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4 ) # impulse response function var.irf = sovereign::IRF(var) # local projection forecasts lp = sovereign::LP( data = Data, horizon = c(1:10), lag.ic = 'AIC', lag.max = 4, type = 'both', freq = 'month') # LP impulse response function lp.irf = sovereign::IRF(lp)
Estimate local projections
LP( data, horizons = 1, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, NW = FALSE, NW_lags = NULL, NW_prewhite = NULL )
LP( data, horizons = 1, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, NW = FALSE, NW_lags = NULL, NW_prewhite = NULL )
data |
data.frame, matrix, ts, xts, zoo: Endogenous regressors |
horizons |
int: forecast horizons |
freq |
string: frequency of data ('day', 'week', 'month', 'quarter', or 'year') |
type |
string: type of deterministic terms to add ('none', 'const', 'trend', or 'both') |
p |
int: lags |
lag.ic |
string: information criterion to choose the optimal number of lags ('AIC' or 'BIC') |
lag.max |
int: maximum number of lags to test in lag selection |
NW |
boolean: Newey-West correction on variance-covariance matrix |
NW_lags |
int: number of lags to use in Newey-West correction |
NW_prewhite |
boolean: TRUE prewhite option for Newey-West correction (see sandwich::NeweyWest) |
list object with elements data
, model
, forecasts
, residuals
; if there is more than one forecast horizon estimated, then model
, forecasts
, residuals
will each be a list where each element corresponds to a single horizon
Jorda, Oscar "Estimation and Inference of Impulse Responses by Local Projections" 2005.
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # local projection forecasts lp = sovereign::LP( data = Data, horizon = c(1:10), lag.ic = 'AIC', lag.max = 4, type = 'both', freq = 'month') # impulse response function irf = sovereign::lp_irf(lp)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # local projection forecasts lp = sovereign::LP( data = Data, horizon = c(1:10), lag.ic = 'AIC', lag.max = 4, type = 'both', freq = 'month') # impulse response function irf = sovereign::lp_irf(lp)
Estimate impulse response functions
lp_irf(lp, CI = c(0.1, 0.9), regime = NULL)
lp_irf(lp, CI = c(0.1, 0.9), regime = NULL)
lp |
LP output |
CI |
numeric vector: c(lower ci bound, upper ci bound) |
regime |
string: indicates regime index column of data |
long-form data.frame with one row per target-shock-horizon identifier
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # local projection forecasts lp = sovereign::LP( data = Data, horizon = c(1:10), lag.ic = 'AIC', lag.max = 4, type = 'both', freq = 'month') # impulse response function irf = sovereign::lp_irf(lp)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # local projection forecasts lp = sovereign::LP( data = Data, horizon = c(1:10), lag.ic = 'AIC', lag.max = 4, type = 'both', freq = 'month') # impulse response function irf = sovereign::lp_irf(lp)
Chart residuals
plot_error(residuals, series = NULL, verticle = FALSE)
plot_error(residuals, series = NULL, verticle = FALSE)
residuals |
data.frame: sovereign residuals object |
series |
string: series to plot (default to all series) |
verticle |
boolean: If true then stack all plots into one column |
grid of ggplot2 graphs
Chart FEVDs
plot_fevd(fevd, responses = NULL, verticle = FALSE)
plot_fevd(fevd, responses = NULL, verticle = FALSE)
fevd |
fevd object |
responses |
string vector: responses to plot |
verticle |
boolean: If true then stack all plots into one column |
grid of ggplot2 graphs
Chart forecasts
plot_forecast(forecasts, series = NULL, verticle = FALSE)
plot_forecast(forecasts, series = NULL, verticle = FALSE)
forecasts |
data.frame: sovereign forecast object |
series |
string: series to plot (default to all series) |
verticle |
boolean: If true then stack all plots into one column |
grid of ggplot2 graphs
Chart HDs
plot_hd(hd, verticle = FALSE)
plot_hd(hd, verticle = FALSE)
hd |
hd object |
verticle |
boolean: If true then stack all plots into one column |
grid of ggplot2 graphs
Chart individual residuals
plot_individual_error( data, target, title = NULL, ylab = NULL, freq = NULL, zeroline = FALSE )
plot_individual_error( data, target, title = NULL, ylab = NULL, freq = NULL, zeroline = FALSE )
data |
data.frame: sovereign residuals object |
target |
string: series to plot |
title |
string: chart title |
ylab |
string: y-axis label |
freq |
string: frequency (acts as sub-title) |
zeroline |
boolean: if TRUE then add a horizontal line at zero |
ggplot2 chart
Plot an individual FEVD
plot_individual_fevd(fevd, response.var, title, ylab)
plot_individual_fevd(fevd, response.var, title, ylab)
fevd |
fevd object |
response.var |
string: name of variable to treat as the response |
title |
string: title of the chart |
ylab |
string: y-axis label |
ggplot2 graph
Chart individual forecast
plot_individual_forecast( data, target, title = NULL, ylab = NULL, freq = NULL, zeroline = FALSE )
plot_individual_forecast( data, target, title = NULL, ylab = NULL, freq = NULL, zeroline = FALSE )
data |
data.frame: sovereign model forecast |
target |
string: series to plot |
title |
string: chart title |
ylab |
string: y-axis label |
freq |
string: frequency (acts as sub-title) |
zeroline |
boolean: if TRUE then add a horizontal line at zero |
ggplot2 chart
Plot an individual HD
plot_individual_hd(hd, target.var, title)
plot_individual_hd(hd, target.var, title)
hd |
hd object |
target.var |
string: name of variable to decompose into shocks |
title |
string: title of the chart |
ggplot2 graph
Plot an individual IRF
plot_individual_irf(irf, shock.var, response.var, title, ylab)
plot_individual_irf(irf, shock.var, response.var, title, ylab)
irf |
irf object |
shock.var |
string: name of variable to treat as the shock |
response.var |
string: name of variable to treat as the response |
title |
string: title of the chart |
ylab |
string: y-axis label |
ggplot2 graph
Chart IRFs
plot_irf(irf, shocks = NULL, responses = NULL, verticle = FALSE)
plot_irf(irf, shocks = NULL, responses = NULL, verticle = FALSE)
irf |
irf object |
shocks |
string vector: shocks to plot |
responses |
string vector: responses to plot |
verticle |
boolean: If true then stack all plots into one column |
grid of ggplot2 graphs
Regime assignment (clustering) methods available include the unsupervised random forest, k-mean clustering, Fraley and Raftery Model-based clustering EM algorithm, and the Bai & Perron (2003) method for simultaneous estimation of multiple breakpoints.
regimes(data, method = "rf", regime.n = NULL)
regimes(data, method = "rf", regime.n = NULL)
data |
data.frame, matrix, ts, xts, zoo: Endogenous regressors |
method |
string: regime assignment technique ('rf', 'kmeans', 'EM', or 'BP) |
regime.n |
int: number of regimes to estimate (applies to kmeans and EM) |
data
as a data.frame with a regime column assigning rows to mutually exclusive regimes
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate reigme regime = sovereign::regimes( data = Data, method = 'kmeans', regime.n = 3)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate reigme regime = sovereign::regimes( data = Data, method = 'kmeans', regime.n = 3)
Estimate a regime-dependent local projection (i.e. a state-dependent LP), with an exogenous state indicator, of the specification:
where t is the time index, and s is a mutually exclusive state of the world observed at time t. When the regime vector is not supplied by the user, then a two-state regime series is estimated via random forest.
RLP( data, horizons = 1, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, NW = FALSE, NW_lags = NULL, NW_prewhite = NULL, regime = NULL, regime.method = "rf", regime.n = 2 )
RLP( data, horizons = 1, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, NW = FALSE, NW_lags = NULL, NW_prewhite = NULL, regime = NULL, regime.method = "rf", regime.n = 2 )
data |
data.frame, matrix, ts, xts, zoo: Endogenous regressors |
horizons |
int: forecast horizons |
freq |
string: frequency of data ('day', 'week', 'month', 'quarter', or 'year') |
type |
string: type of deterministic terms to add ('none', 'const', 'trend', or 'both') |
p |
int: lags |
lag.ic |
string: information criterion to choose the optimal number of lags ('AIC' or 'BIC') |
lag.max |
int: maximum number of lags to test in lag selection |
NW |
boolean: Newey-West correction on variance-covariance matrix |
NW_lags |
int: number of lags to use in Newey-West correction |
NW_prewhite |
boolean: TRUE prewhite option for Newey-West correction (see sandwich::NeweyWest) |
regime |
string: name or regime assignment vector in the design matrix (data) |
regime.method |
string: regime assignment technique ('rf', 'kmeans', 'EM', 'BP') |
regime.n |
int: number of regimes to estimate (applies to kmeans and EM) |
list of lists, one list per regime, each regime with objects with elements data
, model
, forecasts
, residuals
;
if there is more than one forecast horizon estimated, then model
, forecasts
, residuals
will each be a list where each element corresponds to a single horizon
Jorda, Oscar "Estimation and Inference of Impulse Responses by Local Projections" 2005.
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # add regime Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # local projection forecasts rlp = sovereign::RLP( data = Data, regime = 'reg', horizon = c(1:10), freq = 'month', p = 1, type = 'const', NW = TRUE, NW_lags = 1, NW_prewhite = FALSE) # impulse response function rirf = sovereign::rlp_irf(rlp)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # add regime Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # local projection forecasts rlp = sovereign::RLP( data = Data, regime = 'reg', horizon = c(1:10), freq = 'month', p = 1, type = 'const', NW = TRUE, NW_lags = 1, NW_prewhite = FALSE) # impulse response function rirf = sovereign::rlp_irf(rlp)
Estimate regime-dependent impulse response functions
rlp_irf(rlp, CI = c(0.1, 0.9))
rlp_irf(rlp, CI = c(0.1, 0.9))
rlp |
RLP output |
CI |
numeric vector: c(lower ci bound, upper ci bound) |
list of long-form data.frame with one row per target-shock-horizon identifier
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # add regime Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # local projection forecasts rlp = sovereign::RLP( data = Data, regime = 'reg', horizon = c(1:10), freq = 'month', p = 1,, type = 'const', NW = TRUE, NW_lags = 1, NW_prewhite = FALSE) # impulse response function rirf = sovereign::rlp_irf(rlp)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # add regime Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # local projection forecasts rlp = sovereign::RLP( data = Data, regime = 'reg', horizon = c(1:10), freq = 'month', p = 1,, type = 'const', NW = TRUE, NW_lags = 1, NW_prewhite = FALSE) # impulse response function rirf = sovereign::rlp_irf(rlp)
Estimate a regime-dependent VAR (i.e. a state-dependent VAR), with an exogenous state indicator, of the specification:
where t is the time index, Y is the set of outcome vectors, X the design matrix (of p lagged values of Y), and s is a mutually exclusive state of the world observed at time t. When the regime vector is not supplied by the user, then a two-state regime series is estimated via random forest.
RVAR( data, horizon = 10, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, regime = NULL, regime.method = "rf", regime.n = 2, structure = "short", instrument = NULL, instrumented = NULL )
RVAR( data, horizon = 10, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, regime = NULL, regime.method = "rf", regime.n = 2, structure = "short", instrument = NULL, instrumented = NULL )
data |
data.frame, matrix, ts, xts, zoo: Endogenous regressors |
horizon |
int: forecast horizons |
freq |
string: frequency of data ('day', 'week', 'month', 'quarter', or 'year') |
type |
string: type of deterministic terms to add ('none', 'const', 'trend', or 'both') |
p |
int: lags |
lag.ic |
string: information criterion to choose the optimal number of lags ('AIC' or 'BIC') |
lag.max |
int: maximum number of lags to test in lag selection |
regime |
string: name or regime assignment vector in the design matrix (data) |
regime.method |
string: regime assignment technique ('rf', 'kmeans', 'EM', or 'BP') |
regime.n |
int: number of regimes to estimate (applies to kmeans and EM) |
structure |
string: type of structural identification strategy to use in model analysis (NA, 'short', 'IV', or 'IV-short') |
instrument |
string: name of instrumental variable contained in the data matrix |
instrumented |
string: name of variable to be instrumented in IV and IV-short procedure; default is the first non-date variable in data |
The regime-dependent VAR is a generalization of the popular threshold VAR - which trades off estimating a threshold value for an endogenous variable for accepting an exogenous regime that can be based on information from inside or outside of the system, with or without parametric assumptions, and with or without timing restrictions. Moreover, the RVAR may be extended to include structural shocks, including the use of instrumental variables.
State dependence. The RVAR augments the traditional VAR by allowing state-dependence in the coefficient matrix. The RVAR differs from the more common threshold VAR (TVAR), due
to the fact that states are exegonesouly determined. As a result, the states (i.e. regimes) do not need to be based on information inside the model, moreover, regimes can be
determined by any process the user determines best fits their needs. For example, regimes based on NBER dated recessions and expansions are based on a judgmental process
considering hundreds of series, potentially none of which are in the VAR being modeled. Alternatively, a user may use unsupervised machine learning to assign regimes - this is
the process the sovereign::regimes
function facilitates.
Structural shocks. See Sims (1980) for details regarding the baseline vector-autoregression (VAR) model. The VAR may be augmented to become a structural VAR (SVAR) with one of three different structural identification strategies:
short-term impact restrictions via Cholesky decomposition, see Christiano et al (1999) for details (structure = 'short')
external instrument identification, i.e. a Proxy-SVAR strategy, see Mertens and Ravn (2013) for details (structure = 'IV')
or a combination of short-term and IV identification via Lunsford (2015) (structure = 'IV-short')
Note that including structure does not change the estimation of model coefficients or forecasts, but does change impulse response functions, forecast error variance decomposition, and historical decompositions. Historical decompositions will not be available for models using the 'IV' structure. Additionally note that only one instrument may be used in this estimation routine.
List of lists, where each regime is a list with items:
data: data.frame with endogenous variables and 'date' column.
model: list with data.frame of model coefficients (in psuedo-companion form), data.frame of coefficient standard errors, integer of lags p, integer of horizons, string of frequency, string of deterministic term type, numeric of log-likelihood, regime indicator
forecasts: list of data.frames per horizon; data.frame with column for date (day the forecast was made), forecast.date (the date being forecasted), target (variable forecasted), and forecast
residuals: list of data.frames per horizon; data.frame of residuals
structure: string denoting which structural identification strategy will be used in analysis (or NA)
instrument: data.frame with 'date' column and 'instrument' column (or NULL)
instrumented: string denoting which column will be instrumted in 'IV' and 'IV-short' strategies (or NULL)
Christiano, Lawrence, Martin Eichenbaum, and Charles Evans "Monetary policy shocks: What have we learned and to what end?" Handbook of Macroeconomics, Vol 1, Part A, 1999.
Lunsford, Kurt "Identifying Structural VARs with a Proxy Variable and a Test for a Weak Proxy" 2015.
Mertens, Karel and Morten Ravn "The Dynamic Effects of Personal and Corporate Income Tax Changes in the United States" 2013.
Sims, Christopher "Macroeconomics and Reality" 1980.
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate regime-dependent VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate regime-dependent VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
Estimate forecast error variance decomposition for RVARs with either short or 'IV-short' structural errors.
rvar_fevd(rvar, horizon = 10, scale = TRUE)
rvar_fevd(rvar, horizon = 10, scale = TRUE)
rvar |
RVAR output |
horizon |
int: number of periods |
scale |
boolean: scale variable contribution as percent of total error |
list, each regime returns its own long-form data.frame
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
Estimate historical decomposition for RVARs with either short or 'IV-short' structural errors.
rvar_hd(rvar)
rvar_hd(rvar)
rvar |
RVAR output |
long form data.frames
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
Estimate regime-dependent impulse response functions
rvar_irf( rvar, horizon = 10, CI = c(0.1, 0.9), bootstrap.type = "auto", bootstrap.num = 100, bootstrap.parallel = FALSE, bootstrap.cores = -1 )
rvar_irf( rvar, horizon = 10, CI = c(0.1, 0.9), bootstrap.type = "auto", bootstrap.num = 100, bootstrap.parallel = FALSE, bootstrap.cores = -1 )
rvar |
RVAR output |
horizon |
int: number of periods |
CI |
numeric vector: c(lower ci bound, upper ci bound) |
bootstrap.type |
string: bootstrapping technique to use ('auto', 'standard', or 'wild'); if auto then wild is used for IV or IV-short, else standard is used |
bootstrap.num |
int: number of bootstraps |
bootstrap.parallel |
boolean: create IRF draws in parallel |
bootstrap.cores |
int: number of cores to use in parallel processing; -1 detects and uses half the available cores |
list of regimes, each with data.frame of columns target
, shock
, horizon
, response.lower
, response
, response.upper
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) Data = dplyr::mutate(Data, reg = dplyr::if_else(AA > median(AA), 1, 0)) # estimate VAR rvar = sovereign::RVAR( data = Data, horizon = 10, freq = 'month', regime.method = 'rf', regime.n = 2, lag.ic = 'BIC', lag.max = 4) # impulse response functions rvar.irf = sovereign::rvar_irf(rvar) # forecast error variance decomposition rvar.fevd = sovereign::rvar_fevd(rvar) # historical shock decomposition rvar.hd = sovereign::rvar_hd(rvar)
Estimate VAR, SVAR, or Proxy-SVAR
VAR( data, horizon = 10, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, structure = "short", instrument = NULL, instrumented = NULL )
VAR( data, horizon = 10, freq = "month", type = "const", p = 1, lag.ic = NULL, lag.max = NULL, structure = "short", instrument = NULL, instrumented = NULL )
data |
data.frame, matrix, ts, xts, zoo: Endogenous regressors |
horizon |
int: forecast horizons |
freq |
string: frequency of data ('day', 'week', 'month', 'quarter', or 'year') |
type |
string: type of deterministic terms to add ('none', 'const', 'trend', or 'both') |
p |
int: lags |
lag.ic |
string: information criterion to choose the optimal number of lags ('AIC' or 'BIC') |
lag.max |
int: maximum number of lags to test in lag selection |
structure |
string: type of structural identification strategy to use in model analysis (NA, 'short', 'IV', or 'IV-short') |
instrument |
string: name of instrumental variable contained in the data matrix |
instrumented |
string: name of variable to be instrumented in IV and IV-short procedure; default is the first non-date variable in data |
See Sims (1980) for details regarding the baseline vector-autoregression (VAR) model. The VAR may be augmented to become a structural VAR (SVAR) with one of three different structural identification strategies:
short-term impact restrictions via Cholesky decomposition, see Christiano et al (1999) for details (structure = 'short')
external instrument identification, i.e. a Proxy-SVAR strategy, see Mertens and Ravn (2013) for details (structure = 'IV')
or a combination of short-term and IV identification via Lunsford (2015) (structure = 'IV-short')
Note that including structure does not change the estimation of model coefficients or forecasts, but does change impulse response functions, forecast error variance decomposition, and historical decompositions. Historical decompositions will not be available for models using the 'IV' structure. Additionally note that only one instrument may be used in this estimation routine.
data: data.frame with endogenous variables and 'date' column.
model: list with data.frame of model coefficients (in psuedo-companion form), data.frame of coefficient standard errors, integer of lags p, integer of horizons, string of frequency, string of deterministic term type, numeric of log-likelihood
forecasts: list of data.frames per horizon; data.frame with column for date (day the forecast was made), forecast.date (the date being forecasted), target (variable forecasted), and forecast
residuals: list of data.frames per horizon; data.frame of residuals
structure: string denoting which structural identification strategy will be used in analysis (or NA)
instrument: data.frame with 'date' column and 'instrument' column (or NULL)
instrumented: string denoting which column will be instrumted in 'IV' and 'IV-short' strategies (or NA)
Christiano, Lawrence, Martin Eichenbaum, and Charles Evans "Monetary policy shocks: What have we learned and to what end?" Handbook of Macroeconomics, Vol 1, Part A, 1999.
Lunsford, Kurt "Identifying Structural VARs with a Proxy Variable and a Test for a Weak Proxy" 2015.
Mertens, Karel and Morten Ravn "The Dynamic Effects of Personal and Corporate Income Tax Changes in the United States" 2013.
Sims, Christopher "Macroeconomics and Reality" 1980.
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
Estimate forecast error variance decomposition for VARs with either short or 'IV-short' structural errors.
var_fevd(var, horizon = 10, scale = TRUE)
var_fevd(var, horizon = 10, scale = TRUE)
var |
VAR output |
horizon |
int: number of periods |
scale |
boolean: scale variable contribution as percent of total error |
long-form data.frame
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
Estimate historical decomposition for VARs with either short or 'IV-short' structural errors.
var_hd(var)
var_hd(var)
var |
VAR output |
long-from data.frame
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
Estimate impulse response functions
var_irf( var, horizon = 10, CI = c(0.1, 0.9), bootstrap.type = "auto", bootstrap.num = 100, bootstrap.parallel = FALSE, bootstrap.cores = -1 )
var_irf( var, horizon = 10, CI = c(0.1, 0.9), bootstrap.type = "auto", bootstrap.num = 100, bootstrap.parallel = FALSE, bootstrap.cores = -1 )
var |
VAR output |
horizon |
int: number of periods |
CI |
numeric vector: c(lower ci bound, upper ci bound) |
bootstrap.type |
string: bootstrapping technique to use ('auto', 'standard', or 'wild'); if auto then wild is used for IV or IV-short, else standard is used |
bootstrap.num |
int: number of bootstraps |
bootstrap.parallel |
boolean: create IRF draws in parallel |
bootstrap.cores |
int: number of cores to use in parallel processing; -1 detects and uses half the available cores |
data.frame with columns target
, shock
, horizon
, response.lower
, response
, response.upper
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)
# simple time series AA = c(1:100) + rnorm(100) BB = c(1:100) + rnorm(100) CC = AA + BB + rnorm(100) date = seq.Date(from = as.Date('2000-01-01'), by = 'month', length.out = 100) Data = data.frame(date = date, AA, BB, CC) # estimate VAR var = sovereign::VAR( data = Data, horizon = 10, freq = 'month', lag.ic = 'BIC', lag.max = 4) # impulse response functions var.irf = sovereign::var_irf(var) # forecast error variance decomposition var.fevd = sovereign::var_fevd(var) # historical shock decomposition var.hd = sovereign::var_hd(var)