Type: | Package |
Title: | Toolkit for Reduced Form and Structural Smooth Transition Vector Autoregressive Models |
Version: | 1.2.1 |
Author: | Savi Virolainen |
Maintainer: | Savi Virolainen <savi.virolainen@helsinki.fi> |
Description: | Penalized and non-penalized maximum likelihood estimation of smooth transition vector autoregressive models with various types of transition weight functions, conditional distributions, and identification methods. Constrained estimation with various types of constraints is available. Residual based model diagnostics, forecasting, simulations, counterfactual analysis, and computation of impulse response functions, generalized impulse response functions, generalized forecast error variance decompositions, as well as historical decompositions. See Heather Anderson, Farshid Vahid (1998) <doi:10.1016/S0304-4076(97)00076-6>, Helmut Lütkepohl, Aleksei Netšunajev (2017) <doi:10.1016/j.jedc.2017.09.001>, Markku Lanne, Savi Virolainen (2025) <doi:10.48550/arXiv.2403.14216>, Savi Virolainen (2025) <doi:10.48550/arXiv.2404.19707>. |
Depends: | R (≥ 4.0.0) |
URL: | https://github.com/saviviro/sstvars |
BugReports: | https://github.com/saviviro/sstvars/issues |
SystemRequirements: | BLAS, LAPACK |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
LinkingTo: | Rcpp, RcppArmadillo |
Imports: | Rcpp (≥ 1.0.0), RcppArmadillo (≥ 0.12.0.0.0), parallel (≥ 4.0.0), pbapply (≥ 1.7-0), stats (≥ 4.0.0), graphics (≥ 4.0.0), utils (≥ 4.0.0) |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
NeedsCompilation: | yes |
Packaged: | 2025-06-19 14:20:23 UTC; savi |
Repository: | CRAN |
Date/Publication: | 2025-06-19 15:30:02 UTC |
sstvars: toolkit for reduced form and structural smooth transition vector autoregressive models
Description
sstvars
is a package for reduced form and structural smooth transition vector
autoregressive models. The package implements various transition weight functions, conditional distributions,
identification methods, and parameter restrictions. The model parameters are estimated with the method of maximum
likelihood or penalized maximum likelihood by running multiple rounds of either a two-phase estimation procedure
or a three-phase procedure. In the former, a genetic algorithm is used to find starting values for a gradient based
variable metric algorithm. In the latter, nonlinear least squares (NLS) first used obtain initial estimates for some
of the parameters, then a genetic algorithm is used to find starting values for the rest of the parameters conditional
on the NLS estimates, and finally a gradient based variable metric algorithm is initialized from the estimates obtained
from the previous two steps. For evaluating the adequacy of the estimated models, sstvars
utilizes residuals based
diagnostics and provides functions for graphical diagnostics as well as for calculating formal diagnostic tests.
sstvars
also accommodates tools for conducting counterfactual analysis as well as computation of impulse
response functions, generalized impulse response functions, generalized forecast error variance decompositions,
and historical decompositions. Further functionality includes hypothesis testing, plotting the profile log-likelihood
functions about the estimate, simulation from STVAR processes, and forecasting, for example.
The vignette is a good place to start, and see also the readme file.
Author(s)
Maintainer: Savi Virolainen savi.virolainen@helsinki.fi (ORCID)
See Also
Useful links:
Genetic algorithm for preliminary estimation of reduced form STVAR models
Description
GAfit
estimates the specified reduced form STVAR model using a genetic algorithm.
It is designed to find starting values for gradient based methods and NOT to obtain final estimates
constituting a local maximum.
Usage
GAfit(
data,
p,
M,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
ngen = 200,
popsize,
smart_mu = min(100, ceiling(0.5 * ngen)),
initpop = NULL,
mu_scale,
mu_scale2,
omega_scale,
B_scale,
weight_scale,
ar_scale = 0.2,
upper_ar_scale = 1,
ar_scale2 = 1,
regime_force_scale = 1,
penalized,
penalty_params = c(0.05, 0.5),
allow_unstab,
red_criteria = c(0.05, 0.01),
bound_by_weights = FALSE,
min_obs_coef_ga = 2.5,
pre_smart_mu_prob = 0,
to_return = c("alt_ind", "best_ind"),
minval,
fixed_params = NULL,
fixed_params_in_smart_mu = TRUE,
seed = NULL
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
ngen |
a positive integer specifying the number of generations to be ran through in the genetic algorithm. |
popsize |
a positive even integer specifying the population size in the genetic algorithm.
Default is |
smart_mu |
a positive integer specifying the generation after which the random mutations in the genetic algorithm are "smart". This means that mutating individuals will mostly mutate fairly close (or partially close) to the best fitting individual (which has the least regimes with time varying mixing weights practically at zero) so far. |
initpop |
a list of parameter vectors from which the initial population of the genetic algorithm
will be generated from. The parameter vectors hould have the form
For models with...
Above, |
mu_scale |
a size |
mu_scale2 |
a size |
omega_scale |
a size |
B_scale |
a size |
weight_scale |
For...
|
ar_scale |
a positive real number between zero and one adjusting how large AR parameter values are typically
proposed in construction of the initial population: larger value implies larger coefficients (in absolute value).
After construction of the initial population, a new scale is drawn from |
upper_ar_scale |
the upper bound for |
ar_scale2 |
a positive real number adjusting how large AR parameter values are typically proposed in some random mutations (if AR constraints are employed, in all random mutations): larger value implies smaller coefficients (in absolute value). Values larger than 1 can be used if the AR coefficients are expected to be very small. If set smaller than 1, be careful as it might lead to failure in the creation of parameter candidates that satisfy the stability condition. |
regime_force_scale |
a non-negative real number specifying how much should natural selection favor individuals
with less regimes that have almost all mixing weights (practically) at zero. Set to zero for no favoring or large
number for heavy favoring. Without any favoring the genetic algorithm gets more often stuck in an area of the
parameter space where some regimes are wasted, but with too much favouring the best genes might never mix into
the population and the algorithm might converge poorly. Default is |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
red_criteria |
a length 2 numeric vector specifying the criteria that is used to determine whether a regime is
redundant (or "wasted") or not.
Any regime |
bound_by_weights |
should the parameter space be constrained to areas where the transition weights do allocate
enough weights to each regime compared to the number of observations in the regime? See the argument |
min_obs_coef_ga |
if |
pre_smart_mu_prob |
A number in |
to_return |
should the genetic algorithm return the best fitting individual which has "positive enough" mixing
weights for as many regimes as possible ( |
minval |
a real number defining the minimum value of the log-likelihood function that will be considered.
Values smaller than this will be treated as they were |
fixed_params |
a vector containing fixed parameter values for intercept, autoregressive, and weight parameters
that should be fixed in the initial population. Should have the form:
For models with...
Note that |
fixed_params_in_smart_mu |
should the fixed parameters be fixed in the smart mutation phase as well? If |
seed |
a single value, interpreted as an integer, or NULL, that sets seed for the random number generator in
the beginning of the function call. If calling |
Details
Only reduced form models are supported!
The core of the genetic algorithm is mostly based on the description by Dorsey and Mayer (1995). It utilizes a slightly modified version of the individually adaptive crossover and mutation rates described by Patnaik and Srinivas (1994) and employs (50%) fitness inheritance discussed by Smith, Dike and Stegmann (1995).
By "redundant" or "wasted" regimes we mean regimes that have the time varying mixing weights practically at zero for almost all t. A model including redundant regimes would have about the same log-likelihood value without the redundant regimes and there is no purpose to have redundant regimes in a model.
Some of the AR coefficients are drawn with the algorithm by Ansley and Kohn (1986). However,
when using large ar_scale
with large p
or d
, numerical inaccuracies caused
by the imprecision of the float-point presentation may result in errors or nonstationary AR-matrices.
Using smaller ar_scale
facilitates the usage of larger p
or d
. Therefore, we bound
upper_ar_scale
from above by 1-pd/150
when p*d>40
and by 1
otherwise.
Structural models are not supported here, as they are best estimated based on reduced form parameter estimates
using the function fitSSTVAR
.
Value
Returns the estimated parameter vector which has the form described in initpop
,
with the exception that for models with cond_dist == "ind_Student"
or
"ind_skewed_t"
, the parameter vector is parametrized with B_1,B_2^*,...,B_M^*
instead of B_1,B_2,...,B_M
, where B_m^* = B_m - B_1
. Use the function change_parametrization
to change back to the original parametrization if desired.
References
Ansley C.F., Kohn R. 1986. A note on reparameterizing a vector autoregressive moving average model to enforce stationarity. Journal of statistical computation and simulation, 24:2, 99-106.
Dorsey R. E. and Mayer W. J. 1995. Genetic algorithms for estimation problems with multiple optima, nondifferentiability, and other irregular features. Journal of Business & Economic Statistics, 13, 53-66.
Patnaik L.M. and Srinivas M. 1994. Adaptive Probabilities of Crossover and Mutation in Genetic Algorithms. Transactions on Systems, Man and Cybernetics 24, 656-667.
Smith R.E., Dike B.A., Stegmann S.A. 1995. Fitness inheritance in genetic algorithms. Proceedings of the 1995 ACM Symposium on Applied Computing, 345-350.
Estimate generalized forecast error variance decomposition for structural STVAR models.
Description
GFEVD
estimates generalized forecast error variance decomposition
for structural STVAR models.
Usage
GFEVD(
stvar,
N = 30,
shock_size = 1,
initval_type = c("data", "random", "fixed"),
which_cumulative = numeric(0),
use_data_shocks = FALSE,
data_gfevd_pars = c(0, 0.75),
init_regime = 1,
init_values = NULL,
R1 = 250,
R2 = 250,
ncores = 2,
burn_in = 1000,
exo_weights = NULL,
seeds = NULL,
use_parallel = TRUE
)
## S3 method for class 'gfevd'
plot(x, ..., data_shock_pars = NULL)
## S3 method for class 'gfevd'
print(x, ..., digits = 2, N_to_print)
Arguments
stvar |
an object of class |
N |
a positive integer specifying the horizon how far ahead should the GFEVD be calculated. |
shock_size |
What sign and size should be used for all shocks? By the normalization, the conditional covariance matrix of the structural error is an identity matrix. |
initval_type |
What type initial values are used for estimating the GIRFs that the GFEVD is based on?
|
which_cumulative |
a numeric vector with values in |
use_data_shocks |
set |
data_gfevd_pars |
a length two numeric vector with the following elements determining settings for
|
init_regime |
an integer in |
init_values |
a size |
R1 |
the number of repetitions used to estimate GIRF for each initial value. |
R2 |
the number of initial values to be drawn/used if |
ncores |
the number CPU cores to be used in parallel computing. Only single core computing is supported if an initial value is specified (and the GIRF won't thus be estimated multiple times). |
burn_in |
Burn-in period for simulating initial values from a regime. |
exo_weights |
if |
seeds |
a numeric vector containing the random number generator seed for estimation of each GIRF. Should have the length of at least...
If the length of the vector is greater than what is needed, the extra seeds are dropped from the
end of the |
use_parallel |
employ parallel computing? If |
x |
object of class |
... |
graphical parameters passed to the |
data_shock_pars |
if |
digits |
the number of decimals to print |
N_to_print |
an integer specifying the horizon how far to print the estimates. The default is that all the values are printed. |
Details
The GFEVD is a forecast error variance decomposition calculated with the generalized impulse response function (GIRF). See Lanne and Nyberg (2016) for details.
If use_data_shocks=TRUE
, each GIRF in the GFEVD is estimated for a shock that has the sign and size of the
corresponding structural shock recovered from the fitted model. This is done for every possible length p
history
in the data, or to a subset of the histories based in the settings given in the argument data_gfevd_pars
.
The GFEVD is then calculated as the average of the GFEVDs obtained from the GIRFs estimated for
the data shocks. The plot and print methods can be used as usual for this GFEVD, but there is also a special feature
that allows to plot the contribution of each shock to the variance of the forecast errors at various horizons in specific
historical points of time. This can be done by using the plot method with the argument data_shock_pars
.
Note that the arguments shock_size
, initval_type
, and init_regime
are ignored if use_data_shocks=TRUE
.
Value
Returns and object of class 'gfevd' containing the GFEVD for all the variables and to
the transition weights. Note that the decomposition does not exist at horizon zero for transition weights
because the related GIRFs are always zero at impact.
Also contains the individual GFEVDs for each used initial length p
initial value (history) as
4D array with dimensions [horizon, variable, shock, time]
.
Functions
-
plot(gfevd)
: plot method -
print(gfevd)
: print method
References
Lanne M. and Nyberg H. 2016. Generalized Forecast Error Variance Decomposition for Linear and Nonlineae Multivariate Models. Oxford Bulletin of Economics and Statistics, 78, 4, 595-603.
See Also
GIRF
, linear_IRF
, hist_decomp
, cfact_hist
, cfact_fore
,
cfact_girf
, fitSSTVAR
Examples
# These are long-running examples that use parallel computing.
# It takes approximately 30 seconds to run all the below examples.
# Note that larger R1 and R2 should be used for more reliable results;
# small R1 and R2 are used here to shorten the estimation time.
# Recursively identifed logistic Student's t STVAR(p=3, M=2) model with the first
# lag of the second variable as the switching variable:
params32logt <- c(0.5959, 0.0447, 2.6279, 0.2897, 0.2837, 0.0504, -0.2188, 0.4008,
0.3128, 0.0271, -0.1194, 0.1559, -0.0972, 0.0082, -0.1118, 0.2391, 0.164, -0.0363,
-1.073, 0.6759, 3e-04, 0.0069, 0.4271, 0.0533, -0.0498, 0.0355, -0.4686, 0.0812,
0.3368, 0.0035, 0.0325, 1.2289, -0.047, 0.1666, 1.2067, 7.2392, 11.6091)
mod32logt <- STVAR(gdpdef, p=3, M=2, params=params32logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="recursive")
# GFEVD for one-standard-error positive structural shocks, N=30 steps ahead,
# with fix initial values assuming all possible histories in the data.
gfevd1 <- GFEVD(mod32logt, shock_size=1, N=30, initval_type="data", R1=10,
seeds=1:(nrow(mod32logt$data)-2))
print(gfevd1) # Print the results
plot(gfevd1) # Plot the GFEVD
# GFEVD for one-standard-error positive structural shocks, N=30 steps ahead,
# with fix initial values that are the last p observations of the data.
gfevd2 <- GFEVD(mod32logt, shock_size=1, N=30, initval_type="fixed", R1=100, R2=1,
init_values=array(mod32logt$data[(nrow(mod32logt$data) - 2):nrow(mod32logt$data),],
dim=c(3, 2, 1)), seeds=1)
plot(gfevd2) # Plot the GFEVD
# GFEVD for two-standard-error negative structural shocks, N=50 steps ahead
# with the inital values drawn from the first regime. The responses of both
# variables are accumulated.
gfevd3 <- GFEVD(mod32logt, shock_size=-2, N=50, initval_type="random",
R1=50, R2=50, init_regime=1)
plot(gfevd3) # Plot the GFEVD
# GFEVD calculated for each lenght p history in the data in such a way that
# for each history, the structural shock recovered from the fitted model is
# used.
gfevd4 <- GFEVD(mod32logt, N=20, use_data_shocks=TRUE, R1=10)
plot(gfevd4) # The usual plot method
# Plot the contribution of the first to the variance of the forecast errors at
# the historial points of time using the structural shocks recovered from the data:
plot(gfevd4, data_shock_pars=c(1, 0)) # Contribution at impact
plot(gfevd4, data_shock_pars=c(1, 2)) # Contribution after two periods
plot(gfevd4, data_shock_pars=c(1, 4)) # Contribution after four periods
# GFEVD calculated for each length p history in the data in such a way that
# for each history, the structural shock recovered from the fitted model is
# used, and only include the histories in which Regime 1 is dominant (its
# transition weight is at least 0.75):
gfevd5 <- GFEVD(mod32logt, N=20, use_data_shocks=TRUE, data_gfevd_pars=c(1, 0.75),
R1=10)
plot(gfevd5) # Plot the GFEVD
Estimate generalized impulse response function for structural STVAR models.
Description
GIRF
estimates generalized impulse response function for
structural STVAR models.
Usage
GIRF(
stvar,
which_shocks,
shock_size = 1,
N = 30,
R1 = 250,
R2 = 250,
init_regime = 1,
init_values = NULL,
which_cumulative = numeric(0),
scale = NULL,
scale_type = c("instant", "peak"),
scale_horizon = N,
ci = c(0.95, 0.8),
use_data_shocks = FALSE,
data_girf_pars = c(0, 0.75, 0, 0, 1.5),
ncores = 2,
burn_in = 1000,
exo_weights = NULL,
seeds = NULL,
use_parallel = TRUE
)
## S3 method for class 'girf'
plot(x, margs, ...)
## S3 method for class 'girf'
print(x, ..., digits = 2, N_to_print)
Arguments
stvar |
an object of class |
which_shocks |
a numeric vector of length at most |
shock_size |
a non-zero scalar value specifying the common size for all scalar components of the structural shock. Note that the conditional covariance matrix of the structural shock is normalized to an identity matrix and that the (generalized) impulse responses may not be symmetric with respect to the sign and size of the shock. |
N |
a positive integer specifying the horizon how far ahead should the generalized impulse responses be calculated. |
R1 |
the number of repetitions used to estimate GIRF for each initial value. |
R2 |
the number of initial values to use, i.e., to draw from |
init_regime |
an integer in |
init_values |
a size |
which_cumulative |
a numeric vector with values in |
scale |
should the GIRFs to some of the shocks be scaled so that they
correspond to a specific magnitude of instantaneous or peak response
of some specific variable (see the argument |
scale_type |
If argument |
scale_horizon |
If |
ci |
a numeric vector with elements in |
use_data_shocks |
set |
data_girf_pars |
a length five numeric vector with the following elements determining settings for
|
ncores |
the number CPU cores to be used in parallel computing. Only single core computing is supported if an initial value is specified (and the GIRF won't thus be estimated multiple times). |
burn_in |
Burn-in period for simulating initial values from a regime. |
exo_weights |
if |
seeds |
A numeric vector initializing the seeds for the random number generator for estimation of each GIRF. Should have the length of at least (extra seeds are removed from the end of the vector)...
Set |
use_parallel |
employ parallel computing? If |
x |
object of class |
margs |
numeric vector of length four that adjusts the
|
... |
graphical parameters passed to |
digits |
the number of decimals to print |
N_to_print |
an integer specifying the horizon how far to print the estimates and confidence intervals. The default is that all the values are printed. |
Details
The "confidence bounds" do not quantify uncertainty about the true parameter
value but only the initial values (and possibly sign and size of the shock) within the given regime.
If initial values are specified, confidence intervals won't be calculated. Note that if the bounds
look weird in the figure produced by plot.girf
, it is probably because the point estimate is not
inside the bounds. In this case, increasing the argument R2
usually fixes the issue.
Note that if the argument scale
is used, the scaled responses of
the transition weights might be more than one in absolute value.
If weight_function="exogenous"
, exogenous transition weights used in
the Monte Carlo simulations for the future sample paths of the process must
the given in the argument exo_weights
. The same weights are used as
the transition weights across the Monte Carlo repetitions.
If use_data_shocks=TRUE
, the GIRF is estimated using all, or a subset of, the length p histories in the data
as the initial values, and using the sign and size of the corresponding structural shock recovered from the fitted model.
The subset of the length p histories are determined based in the settings given in the argument data_girf_pars
.
Note that the arguments shock_size
and init_regime
are ignored if use_data_shocks=TRUE
.
Value
Returns a class 'girf'
list with the GIRFs in the first
element ($girf_res
) and the used arguments the rest. The first
element containing the GIRFs is a list with the m
th element
containing the point estimates for the GIRF in $point_est
(the first
element) and confidence intervals in $conf_ints
(the second
element). The first row is for the GIRF at impact (n=0)
, the second
for n=1
, the third for n=2
, and so on.
The element $all_girfs
is a list containing results from all the individual GIRFs
obtained from the MC repetitions. Each element is for one shock and results are in
array of the form [horizon, variables, MC-repetitions]
.
Functions
-
plot(girf)
: plot method -
print(girf)
: print method
References
Kilian L., Lütkepohl H. 2017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
See Also
GFEVD
, linear_IRF
, hist_decomp
, cfact_hist
, cfact_fore
,
cfact_girf
, fitSSTVAR
Examples
# These are long-running examples that use parallel computing.
# It takes approximately 30 seconds to run all the below examples.
# Note that larger R1 and R2 should be used for more reliable results;
# small R1 and R2 are used here to shorten the estimation time.
# Recursively identified logistic Student's t STVAR(p=3, M=2) model with the first
# lag of the second variable as the switching variable:
params32logt <- c(0.5959, 0.0447, 2.6279, 0.2897, 0.2837, 0.0504, -0.2188, 0.4008,
0.3128, 0.0271, -0.1194, 0.1559, -0.0972, 0.0082, -0.1118, 0.2391, 0.164, -0.0363,
-1.073, 0.6759, 3e-04, 0.0069, 0.4271, 0.0533, -0.0498, 0.0355, -0.4686, 0.0812,
0.3368, 0.0035, 0.0325, 1.2289, -0.047, 0.1666, 1.2067, 7.2392, 11.6091)
mod32logt <- STVAR(gdpdef, p=3, M=2, params=params32logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="recursive")
# GIRF for one-standard-error positive structural shocks, N=30 steps ahead,
# with the inital values drawn from the first regime.
girf1 <- GIRF(mod32logt, which_shocks=1:2, shock_size=1, N=30, R1=50, R2=50,
init_regime=2)
print(girf1) # Print the results
plot(girf1) # Plot the GIRFs
# GIRF for one-standard-error positive structural shocks, N=30 steps ahead,
# with the inital values drawn from the second regime. The responses of the
# GDP and GDP deflator growth rates are accumulated.
girf2 <- GIRF(mod32logt, which_shocks=1:2, which_cumulative=1:2, shock_size=1,
N=30, R1=50, R2=50, init_regime=2)
plot(girf2) # Plot the GIRFs
# GIRF for two-standard-error negative structural shock - the first shock only.
# N=50 steps ahead with the inital values drawn from the first regime. The responses
# are scaled to correspond an instantanous increase of 0.5 of the first variable.
girf3 <- GIRF(mod32logt, which_shocks=1, shock_size=-2, N=50, R1=50, R2=50,
init_regime=1, scale_type="instant", scale=c(1, 1, 0.5))
plot(girf3) # Plot the GIRFs
# GIRFs for the first shock, using the length p histories in the data where
# the first regime is dominant (its transition weight is at least 0.75),
# the shock is negative, and the size of the shock is less than 1.5.
# The responses are scaled to correspond a unit instantanous increase of the
# first variable.
girf4 <- GIRF(mod32logt, which_shocks=1, N=30, R1=10, use_data_shocks=TRUE,
data_girf_pars=c(1, 0.75, -1, 1, 1.5), scale_type="instant", scale=c(1, 1, 0.5))
plot(girf4) # Plot the GIRFs
INTERNAL Estimate generalized impulse response function for structural STVAR models.
Description
GIRF_int
in an INTERNAL function that estimates generalized impulse response function for
structural STVAR models.
Usage
GIRF_int(
stvar,
which_shocks,
shock_size = 1,
N = 30,
R1 = 250,
R2 = 250,
init_regime = 1,
init_values = NULL,
which_cumulative = numeric(0),
scale = NULL,
scale_type = c("instant", "peak"),
scale_horizon = N,
ci = c(0.95, 0.8),
use_data_shocks = FALSE,
data_girf_pars = c(0, 0.75, 0, 0, 1.5),
ncores = 2,
burn_in = 1000,
exo_weights = NULL,
seeds = NULL,
use_parallel = TRUE,
cfact_pars = NULL
)
Arguments
stvar |
an object of class |
which_shocks |
a numeric vector of length at most |
shock_size |
a non-zero scalar value specifying the common size for all scalar components of the structural shock. Note that the conditional covariance matrix of the structural shock is normalized to an identity matrix and that the (generalized) impulse responses may not be symmetric with respect to the sign and size of the shock. |
N |
a positive integer specifying the horizon how far ahead should the generalized impulse responses be calculated. |
R1 |
the number of repetitions used to estimate GIRF for each initial value. |
R2 |
the number of initial values to use, i.e., to draw from |
init_regime |
an integer in |
init_values |
a size |
which_cumulative |
a numeric vector with values in |
scale |
should the GIRFs to some of the shocks be scaled so that they
correspond to a specific magnitude of instantaneous or peak response
of some specific variable (see the argument |
scale_type |
If argument |
scale_horizon |
If |
ci |
a numeric vector with elements in |
use_data_shocks |
set |
data_girf_pars |
a length five numeric vector with the following elements determining settings for
|
ncores |
the number CPU cores to be used in parallel computing. Only single core computing is supported if an initial value is specified (and the GIRF won't thus be estimated multiple times). |
burn_in |
Burn-in period for simulating initial values from a regime. |
exo_weights |
if |
seeds |
A numeric vector initializing the seeds for the random number generator for estimation of each GIRF. Should have the length of at least (extra seeds are removed from the end of the vector)...
Set |
use_parallel |
employ parallel computing? If |
cfact_pars |
a list parameters used for calculating counterfactual GIRFs (set to
Important: If this is something else than |
Details
The "confidence bounds" do not quantify uncertainty about the true parameter
value but only the initial values (and possibly sign and size of the shock) within the given regime.
If initial values are specified, confidence intervals won't be calculated. Note that if the bounds
look weird in the figure produced by plot.girf
, it is probably because the point estimate is not
inside the bounds. In this case, increasing the argument R2
usually fixes the issue.
Note that if the argument scale
is used, the scaled responses of
the transition weights might be more than one in absolute value.
If weight_function="exogenous"
, exogenous transition weights used in
the Monte Carlo simulations for the future sample paths of the process must
the given in the argument exo_weights
. The same weights are used as
the transition weights across the Monte Carlo repetitions.
If use_data_shocks=TRUE
, the GIRF is estimated using all, or a subset of, the length p histories in the data
as the initial values, and using the sign and size of the corresponding structural shock recovered from the fitted model.
The subset of the length p histories are determined based in the settings given in the argument data_girf_pars
.
Note that the arguments shock_size
and init_regime
are ignored if use_data_shocks=TRUE
.
Value
Returns a class 'girf'
list with the GIRFs in the first
element ($girf_res
) and the used arguments the rest. The first
element containing the GIRFs is a list with the m
th element
containing the point estimates for the GIRF in $point_est
(the first
element) and confidence intervals in $conf_ints
(the second
element). The first row is for the GIRF at impact (n=0)
, the second
for n=1
, the third for n=2
, and so on.
The element $all_girfs
is a list containing results from all the individual GIRFs
obtained from the MC repetitions. Each element is for one shock and results are in
array of the form [horizon, variables, MC-repetitions]
.
References
Kilian L., Lütkepohl H. 2017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
See Also
GFEVD
, linear_IRF
, hist_decomp
, cfact_hist
, cfact_fore
,
cfact_girf
, fitSSTVAR
Calculate log multivariate Gaussian densities
Description
Calculates logs of multivariate Gaussian densities with varying mean and varying covariance matrix AND EXCLUDING the constant term of the density (the constant is calculated and added in R code). The varying conditional covariance matrix is calculated within the function from the regime covariance matrices and transition weights.
Usage
Gaussian_densities_Cpp(obs, means, covmats, alpha_mt)
Arguments
obs |
a |
means |
a |
covmats |
a |
alpha_mt |
a |
Value
a numeric vector containing the multivariate Gaussian densities, excluding the constant term.
Calculate log multivariate Gaussian densities
Description
Calculates logs of multivariate Gaussian densities with constant mean and constant covariance matrix AND EXCLUDING the constant term of the density (the constant is calculated and added in R code).
Usage
Gaussian_densities_const_Cpp(obs, mean, cholcovmat)
Arguments
obs |
a |
mean |
the |
cholcovmat |
the |
Details
This function is used in the relative density transition weights with Gaussian regimes.
Value
a numeric vector containing the multivariate Gaussian densities, excluding the constant term.
Perform likelihood ratio test for a STVAR model
Description
LR_test
performs a likelihood ratio test for a STVAR model
Usage
LR_test(stvar1, stvar2)
Arguments
stvar1 |
an object of class |
stvar2 |
an object of class |
Details
Performs a likelihood ratio test, testing the null hypothesis that the true parameter value lies
in the constrained parameter space. Under the null, the test statistic is asymptotically
\chi^2
-distributed with k
degrees of freedom, k
being the difference in the dimensions
of the unconstrained and constrained parameter spaces.
The test is based on the assumption of the standard result of asymptotic normality! Also, note that this function does not verify that the two models are actually nested.
Value
A list with class "hypotest" containing the test results and arguments used to calculate the test.
References
Buse A. (1982). The Likelihood Ratio, Wald, and Lagrange Multiplier Tests: An Expository Note. The American Statistician, 36(3a), 153-157.
See Also
Wald_test
, Rao_test
, fitSTVAR
, STVAR
,
diagnostic_plot
, profile_logliks
, Portmanteau_test
Examples
# Logistic Student's t STVAR with p=1, M=2, and the first lag of the second variable
# as the switching variable (parameter values were obtained by maximum likelihood estimation;
# fitSTVAR is not used here because the estimation is computationally demanding).
params12 <- c(0.62906848, 0.14245295, 2.41245785, 0.66719269, 0.3534745, 0.06041779, -0.34909745,
0.61783824, 0.125769, -0.04094521, -0.99122586, 0.63805416, 0.371575, 0.00314754, 0.03440824,
1.29072533, -0.06067807, 0.18737385, 1.21813844, 5.00884263, 7.70111672)
fit12 <- STVAR(data=gdpdef, p=1, M=2, params=params12, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student")
fit12
## Test whether the location parameter equals 1:
# Same as the original model but with the location parameter constrained to 1
# (parameter values were obtained by maximum likelihood estimation; fitSTVAR
# is not used here because the estimation is computationally demanding).
params12w <- c(0.6592583, 0.16162866, 1.7811393, 0.38876396, 0.35499367, 0.0576433,
-0.43570508, 0.57337706, 0.16449607, -0.01910167, -0.70747014, 0.75386158, 0.3612087,
0.00241419, 0.03202824, 1.07459924, -0.03432236, 0.14982445, 6.22717097, 8.18575651)
fit12w <- STVAR(data=gdpdef, p=1, M=2, params=params12w, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student",
weight_constraints=list(R=matrix(c(0, 1), nrow=2), r=c(1, 0)))
# Test the null hypothesis of the location parameter equal 1:
LR_test(fit12, fit12w)
## Test whether the means and AR matrices are identical across the regimes:
# Same as the original model but with the mean and AR matrices constrained identical
# across the regimes (parameter values were obtained by maximum likelihood estimation;
# fitSTVAR is not used here because the estimation is computationally demanding).
params12cm <- c(0.76892423, 0.67128089, 0.30824474, 0.03530802, -0.11498402, 0.85942541,
0.39106754, 0.0049437, 0.03897287, 1.44457723, -0.05939876, 0.20885008, 1.23568782,
6.42128475, 7.28733557)
fit12cm <- STVAR(data=gdpdef, p=1, M=2, params=params12cm, weight_function="logistic",
weightfun_pars=c(2, 1), parametrization="mean", cond_dist="Student",
mean_constraints=list(1:2), AR_constraints=rbind(diag(4), diag(4)))
# Test the null hypothesis of the means and AR matrices being identical across the regimes:
LR_test(fit12, fit12cm)
Perform adjusted Portmanteau test for a STVAR model
Description
Portmanteau_test
performs adjusted Portmanteau test for remaining autocorrelation
(or heteroskedasticity) in the residuals of a STVAR model.
Usage
Portmanteau_test(stvar, nlags = 20, which_test = c("autocorr", "het.sked"))
Arguments
stvar |
an object of class |
nlags |
a strictly positive integer specifying the number of lags to be tested. |
which_test |
should test for remaining autocorrelation or heteroskedasticity be calculated? |
Details
The implemented adjusted Portmanteau test is based on Lütkepohl (2005), Section 4.4.3. When testing for remaining heteroskedasticity, the Portmanteau test is applied to squared standardized residuals that are centered to have zero mean. Note that the validity of the heteroskedasticity test requires that the residuals are not autocorrelated.
Value
A list with class "hypotest" containing the test results and arguments used to calculate the test.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
See Also
LR_test
, Rao_test
, fitSTVAR
, STVAR
,
diagnostic_plot
, profile_logliks
,
Examples
# Gaussian STVAR p=2, M=2, model with weighted relative stationary densities
# of the regimes as the transition weight function:
theta_222relg <- c(0.357, 0.107, 0.356, 0.086, 0.14, 0.035, -0.165, 0.387, 0.452,
0.013, 0.228, 0.336, 0.239, 0.024, -0.021, 0.708, 0.063, 0.027, 0.009, 0.197,
0.206, 0.005, 0.026, 1.092, -0.009, 0.116, 0.592)
mod222relg <- STVAR(data=gdpdef, p=2, M=2, d=2, params=theta_222relg,
weight_function="relative_dens")
# Test for remaining autocorrelation taking into account the first 20 lags:
Portmanteau_test(mod222relg, nlags=20)
# Test for remaining heteroskedasticity taking into account the first 20 lags:
Portmanteau_test(mod222relg, nlags=20, which_test="het.sked")
# Two-regime Student's t Threhold VAR p=3 model with the first lag of the second
# variable as the switching variable:
theta_322thres <- c(0.527, 0.039, 1.922, 0.154, 0.284, 0.053, 0.033, 0.453, 0.291,
0.024, -0.108, 0.153, -0.108, 0.003, -0.128, 0.219, 0.195, -0.03, -0.893, 0.686,
0.047, 0.016, 0.524, 0.068, -0.025, 0.044, -0.435, 0.119, 0.359, 0.002, 0.038,
1.252, -0.041, 0.151, 1.196, 12.312)
mod322thres <- STVAR(data=gdpdef, p=3, M=2, d=2, params=theta_322thres,
weight_function="threshold", weightfun_pars=c(2, 1), cond_dist="Student")
# Test for remaining autocorrelation taking into account the first 25 lags:
Portmanteau_test(mod322thres, nlags=25)
# Test for remaining heteroskedasticity taking into account the first 25 lags:
Portmanteau_test(mod322thres, nlags=25, which_test="het.sked")
Perform Rao's score test for a STVAR model
Description
Rao_test
performs Rao's score test for a STVAR model
Usage
Rao_test(stvar)
Arguments
stvar |
an object of class |
Details
Tests the constraints imposed in the model given in the argument stvar
.
This implementation uses the outer product of gradients approximation in the test statistic.
The test is based on the assumption of the standard result of asymptotic normality!
Value
A list with class "hypotest" containing the test results and arguments used to calculate the test.
References
Buse A. (1982). The Likelihood Ratio, Wald, and Lagrange Multiplier Tests: An Expository Note. The American Statistician, 36(3a), 153-157.
See Also
LR_test
, Wald_test
, fitSTVAR
, STVAR
,
diagnostic_plot
, profile_logliks
, Portmanteau_test
Examples
## These are long running examples that take approximately 10 seconds to run.
# Logistic Student's t STVAR with p=1, M=2, and the first lag of the second variable
# as the switching variable.
## Test whether the location parameter equal 1:
# The model imposing the constraint on the location parameter (parameter values
# were obtained by maximum likelihood estimation; fitSTVAR is not used here
# because the estimation is computationally demanding):
params12w <- c(0.6592583, 0.16162866, 1.7811393, 0.38876396, 0.35499367, 0.0576433,
-0.43570508, 0.57337706, 0.16449607, -0.01910167, -0.70747014, 0.75386158, 0.3612087,
0.00241419, 0.03202824, 1.07459924, -0.03432236, 0.14982445, 6.22717097, 8.18575651)
fit12w <- STVAR(data=gdpdef, p=1, M=2, params=params12w, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student",
weight_constraints=list(R=matrix(c(0, 1), nrow=2), r=c(1, 0)))
fit12w
# Test the null hypothesis of the location parameter equal 1:
Rao_test(fit12w)
## Test whether the means and AR matrices are identical across the regimes:
# The model imposing the constraint on the location parameter (parameter values
# were obtained by maximum likelihood estimation; fitSTVAR is not used here
# because the estimation is computationally demanding):
params12cm <- c(0.76892423, 0.67128089, 0.30824474, 0.03530802, -0.11498402, 0.85942541,
0.39106754, 0.0049437, 0.03897287, 1.44457723, -0.05939876, 0.20885008, 1.23568782,
6.42128475, 7.28733557)
fit12cm <- STVAR(data=gdpdef, p=1, M=2, params=params12cm, weight_function="logistic",
weightfun_pars=c(2, 1), parametrization="mean", cond_dist="Student",
mean_constraints=list(1:2), AR_constraints=rbind(diag(4), diag(4)))
# Test the null hypothesis of the means and AR matrices being identical across the regimes:
Rao_test(fit12cm)
Create a class 'stvar' object defining a reduced form or structural smooth transition VAR model
Description
STVAR
creates a class 'stvar'
object that defines
a reduced form or structural smooth transition VAR model
Usage
STVAR(
data,
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
penalized = FALSE,
penalty_params = c(0.05, 1),
allow_unstab = FALSE,
calc_std_errors = FALSE
)
## S3 method for class 'stvar'
logLik(object, ...)
## S3 method for class 'stvar'
residuals(object, ...)
## S3 method for class 'stvar'
summary(object, ..., digits = 2, standard_error_print = FALSE)
## S3 method for class 'stvar'
plot(x, ..., plot_type = c("trans_weights", "cond_mean"))
## S3 method for class 'stvar'
print(x, ..., digits = 2, summary_print = FALSE, standard_error_print = FALSE)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
number of times series in the system, i.e. |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
calc_std_errors |
should approximate standard errors be calculated? |
object |
object of class |
... |
currently not used. |
digits |
number of digits to be printed. |
standard_error_print |
if set to |
x |
an object of class |
plot_type |
should the series be plotted with the estimated transition weights or conditional means? |
summary_print |
if set to |
Details
If data is provided, then also residuals are computed and included in the returned object.
The plot displays the time series together with estimated transition weights.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
Functions
-
logLik(stvar)
: Log-likelihood method -
residuals(stvar)
: residuals method to extract Pearson residuals -
summary(stvar)
: summary method -
plot(stvar)
: plot method for class 'stvar' -
print(stvar)
: print method
About S3 methods
If data is not provided, only the print
and simulate
methods are available.
If data is provided, then in addition to the ones listed above, predict
method is also available.
See ?simulate.stvar
and ?predict.stvar
for details about the usage.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hubrich K., Teräsvirta. T. 2013. Thresholds and Smooth Transitions in Vector Autoregressive Models. CREATES Research Paper 2013-18, Aarhus University.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H., Netšunajev A. 2017. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
fitSTVAR
, swap_parametrization
, alt_stvar
Examples
# Below examples use the example data "gdpdef", which is a two-variate quarterly data
# of U.S. GDP and GDP implicit price deflator covering the period from 1959Q1 to 2019Q4.
# Gaussian STVAR p=1, M=2, model with the weighted relative stationary densities
# of the regimes as the transition weight function:
theta_122relg <- c(0.734054, 0.225598, 0.705744, 0.187897, 0.259626, -0.000863,
-0.3124, 0.505251, 0.298483, 0.030096, -0.176925, 0.838898, 0.310863, 0.007512,
0.018244, 0.949533, -0.016941, 0.121403, 0.573269)
mod122 <- STVAR(data=gdpdef, p=1, M=2, params=theta_122relg)
print(mod122) # Printout of the model
summary(mod122) # Summary printout
plot(mod122) # Plot the transition weights
plot(mod122, plot_type="cond_mean") # Plot one-step conditional means
# Logistic Student's t STVAR with p=1, M=2, and the first lag of the second variable
# as the switching variable:
params12 <- c(0.62906848, 0.14245295, 2.41245785, 0.66719269, 0.3534745, 0.06041779, -0.34909745,
0.61783824, 0.125769, -0.04094521, -0.99122586, 0.63805416, 0.371575, 0.00314754, 0.03440824,
1.29072533, -0.06067807, 0.18737385, 1.21813844, 5.00884263, 7.70111672)
fit12 <- STVAR(data=gdpdef, p=1, M=2, params=params12, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student")
summary(fit12) # Summary printout
plot(fit12) # Plot the transition weights
# Threshold STVAR with p=1, M=2, the first lag of the second variable as switching variable:
params12thres <- c(0.5231, 0.1015, 1.9471, 0.3253, 0.3476, 0.0649, -0.035, 0.7513, 0.1651,
-0.029, -0.7947, 0.7925, 0.4233, 5e-04, 0.0439, 1.2332, -0.0402, 0.1481, 1.2036)
mod12thres <- STVAR(data=gdpdef, p=1, M=2, params=params12thres, weight_function="threshold",
weightfun_pars=c(2, 1))
mod12thres # Printout of the model
# Student's t logistic STVAR with p=2, M=2 with the second lag of the second variable
# as the switching variable and structural shocks identified by heteroskedasticity;
# the model created without data:
params22log <- c(0.357, 0.107, 0.356, 0.086, 0.14, 0.035, -0.165, 0.387, 0.452,
0.013, 0.228, 0.336, 0.239, 0.024, -0.021, 0.708, 0.063, 0.027, 0.009, 0.197,
-0.03, 0.24, -0.76, -0.02, 3.36, 0.86, 0.1, 0.2, 7)
mod222logtsh <- STVAR(p=2, M=2, d=2, params=params22log, weight_function="logistic",
weightfun_pars=c(2, 2), cond_dist="Student", identification="heteroskedasticity")
print(mod222logtsh) # Printout of the model
# STVAR p=2, M=2, model with exogenous transition weights and mutually independent
# Student's t shocks:
set.seed(1); tw1 <- runif(nrow(gdpdef)-2) # Transition weights of Regime 1
params22exoit <- c(0.357, 0.107, 0.356, 0.086, 0.14, 0.035, -0.165, 0.387, 0.452,
0.013, 0.228, 0.336, 0.239, 0.024, -0.021, 0.708, 0.063, 0.027, 0.009, 0.197,
-0.1, 0.2, -0.15, 0.13, 0.21, 0.15, 0.11, -0.09, 3, 4)
mod222exoit <- STVAR(p=2, M=2, d=2, params=params22exoit, weight_function="exogenous",
weightfun_pars=cbind(tw1, 1-tw1), cond_dist="ind_Student")
print(mod222exoit) # Printout of the model
# Linear Gaussian VAR(p=1) model:
theta_112 <- c(0.649526, 0.066507, 0.288526, 0.021767, -0.144024, 0.897103,
0.601786, -0.002945, 0.067224)
mod112 <- STVAR(data=gdpdef, p=1, M=1, params=theta_112)
summary(mod112) # Summary printout
Calculate log multivariate Student's t densities
Description
Calculates logs of multivariate Student t densities with varying mean and varying covariance matrix AND EXCLUDING the constant term of the density (the constant is calculated and added in R code). The varying conditional covariance matrix is calculated within the function from the regime covariance matrices and transition weights.
Usage
Student_densities_Cpp(obs, means, covmats, alpha_mt, df)
Arguments
obs |
a |
means |
a |
covmats |
a |
alpha_mt |
a |
df |
the degrees of freedom parameter value (assumed larger than two). |
Details
Note that the parametrization is with the covariance matrix and not the scale matrix.
Value
a numeric vector containing the multivariate Student's t densities, excluding the constant term.
Calculate the dp-dimensional covariance matrix of p consecutive observations of a VAR process
Description
VAR_pcovmat
calculate the dp-dimensional covariance matrix of p consecutive
observations of a VAR process with the algorithm proposed by McElroy (2017).
Usage
VAR_pcovmat(p, d, all_Am, Omega_m)
Arguments
p |
a positive integer specifying the autoregressive order |
d |
the number of time series in the system, i.e., the dimension |
all_Am |
|
Omega_m |
the |
Details
Most of the code in this function is adapted from the one provided in the supplementary material of McElroy (2017). Reproduced under GNU General Public License, Copyright (2015) Tucker McElroy.
Value
Returns the (dp \times dp)
covariance matrix.
References
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Perform Wald test for a STVAR model
Description
Wald_test
performs a Wald test for a STVAR model
Usage
Wald_test(stvar, A, c)
Arguments
stvar |
an object of class |
A |
a size |
c |
a length |
Details
Denoting the true parameter value by \theta_{0}
, we test the null hypothesis A\theta_{0}=c
.
Under the null, the test statistic is asymptotically \chi^2
-distributed with k
(=nrow(A)
) degrees of freedom. The parameter \theta_{0}
is assumed to have the same form as in
the model supplied in the argument stvar
and it is presented in the documentation of the argument
params
in the function STVAR
(see ?STVAR
).
The test is based on the assumption of the standard result of asymptotic normality! Also note that this function does not check whether the model assumptions hold under the null.
Value
A list with class "hypotest" containing the test results and arguments used to calculate the test.
References
Buse A. (1982). The Likelihood Ratio, Wald, and Lagrange Multiplier Tests: An Expository Note. The American Statistician, 36(3a), 153-157.
See Also
LR_test
, Rao_test
, fitSTVAR
, STVAR
,
diagnostic_plot
, profile_logliks
, Portmanteau_test
Examples
# Logistic Student's t STVAR with p=1, M=2, and the first lag of the second variable
# as the switching variable (parameter values were obtained by maximum likelihood estimation;
# fitSTVAR is not used here because the estimation is computationally demanding).
params12 <- c(0.62906848, 0.14245295, 2.41245785, 0.66719269, 0.3534745, 0.06041779, -0.34909745,
0.61783824, 0.125769, -0.04094521, -0.99122586, 0.63805416, 0.371575, 0.00314754, 0.03440824,
1.29072533, -0.06067807, 0.18737385, 1.21813844, 5.00884263, 7.70111672)
fit12 <- STVAR(data=gdpdef, p=1, M=2, params=params12, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student")
fit12
# Test whether the location parameter equals 1.
# For this model, the parameter vector has the length 21 and
# location parameter is in the 19th element:
A <- matrix(c(rep(0, times=18), 1, 0, 0), nrow=1, ncol=21)
c <- 1
Wald_test(fit12, A=A, c=c)
# Test whether the intercepts and autoregressive matrices are identical across the regimes:
# fit12 has parameter vector of length 21. In the first regime, the intercepts are in the
# elements 1,2 and the AR parameters in the elements 5,...,8. In the second regime,
# the intercepts are in the elements 3,4, and the AR parameters the elements 9,...,12.
A <- rbind(cbind(diag(2), -diag(2), matrix(0, nrow=2, ncol=17)), # intercepts
cbind(matrix(0, nrow=4, ncol=4), diag(4), -diag(4), matrix(0, nrow=4, ncol=9))) # AR
c <- rep(0, times=6)
Wald_test(fit12, A=A, c=c)
Vectorization operator that removes zeros
Description
Wvec
stacks columns of the given matrix to form a vector
and removes elements that are zeros.
Usage
Wvec(W)
Arguments
W |
a size |
Value
a vector of length d^2 - n_zeros
where n_zeros
is the
number of zero entries in the matrix W
.
U.S. Actuaries Climate Index, GDP growth rate, CPI, and interest rate data
Description
A monthly U.S. data covering the period from 1961I to 2022III (735 observations) and consisting four variables. First, The Actuaries Climate Index (ACI), which is a measure of the frequency of severe weather and the extend changes in sea levels. Second, the monthly GDP growth rate constructed by the Federal Reserve Bank of Chicago from a collapsed dynamic factor analysis of a panel of 500 monthly measures of real economic activity and quarterly real GDP growth. Third, the monthly growth rate of the consumer price index (CPI). Third, an interest rate variable, which is the effective federal funds rate that is replaced by the the Wu and Xia (2016) shadow rate during zero-lower-bound periods. The Wu and Xia (2016) shadow rate is not bounded by the zero lower bound and also quantifies unconventional monetary policy measures, while it closely follows the federal funds rate when the zero lower bound does not bind.
Usage
acidata
Format
A numeric matrix of class 'ts'
with 735 rows and 4 columns with one time series in each column:
- First column (GDP):
The cyclical component of the log of real GDP, https://fred.stlouisfed.org/series/GDPC1.
- Second column (GDPDEF):
The log-difference of GDP implicit price deflator, https://fred.stlouisfed.org/series/GDPDEF.
- Third column (RATE):
The Federal funds rate from 1954Q3 to 2008Q2 and after that the Wu and Xia (2016) shadow rate, https://fred.stlouisfed.org/series/FEDFUNDS, https://www.atlantafed.org/cqer/research/wu-xia-shadow-federal-funds-rate.
Source
The Federal Reserve Bank of St. Louis database and the Federal Reserve Bank of Atlanta's website
References
American Academy of Actuaries, Canadian Institute of Actuaries, Casualty Actuarial Society, and Society of Actuaries, 2023. Actuaries Climate Index. https://actuariesclimateindex.org.
Federal Reserve Bank of Chicago, 2023. Monthly GDP Growth Rate Data. https://www.chicagofed.org/publications/bbki/index.
Wu J. and Xia F. 2016. Measuring the macroeconomic impact of monetary policy at the zero lower bound. Journal of Money, Credit and Banking, 48(2-3): 253-291.
Check whether all arguments are positive integers
Description
all_pos_ints
checks whether all the elements in a vector
are positive integers.
Usage
all_pos_ints(x)
Arguments
x |
a vector containing the elements to be tested. |
Value
Returns TRUE
or FALSE
accordingly.
Construct a STVAR model based on results from an arbitrary estimation round of fitSTVAR
Description
alt_stvar
constructs a STVAR model based on results from an arbitrary estimation
round of fitSTVAR
Usage
alt_stvar(stvar, which_largest = 1, which_round, calc_std_errors = FALSE)
Arguments
stvar |
object of class |
which_largest |
based on estimation round with which largest log-likelihood should the model be constructed?
An integer value in 1,..., |
which_round |
based on which estimation round should the model be constructed? An integer value in 1,..., |
calc_std_errors |
should approximate standard errors be calculated? |
Details
It's sometimes useful to examine other estimates than the one with the highest log-likelihood. This function
is wrapper around STVAR
that picks the correct estimates from an object returned by fitSTVAR
.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hubrich K., Teräsvirta. T. 2013. Thresholds and Smooth Transitions in Vector Autoregressive Models. CREATES Research Paper 2013-18, Aarhus University.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H., Netšunajev A. 2017. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
Examples
## These are long-running examples that take approximately 10 seconds to run.
# Estimate a Gaussian STVAR p=1, M=2 model with threshold weight function and
# the first lag of the second variable as the switching variables. Run only two
# estimation rounds and use the two-phase estimation method:
fit12 <- fitSTVAR(gdpdef, p=1, M=2, weight_function="threshold", weightfun_pars=c(2, 1),
nrounds=2, seeds=c(1, 4), estim_method="two-phase")
fit12$loglik # Log-likelihood of the estimated model
# Print the log-likelihood obtained from each estimation round:
fit12$all_logliks
# Construct the model based on the second largest log-likelihood found in the
# estimation procedure:
fit12_alt <- alt_stvar(fit12, which_largest=2, calc_std_errors=FALSE)
fit12_alt$loglik # Log-likelihood of the alternative solution
# Construct a model based on a specific estimation round, the first round:
fit12_alt2 <- alt_stvar(fit12, which_round=1, calc_std_errors=FALSE)
fit12_alt2$loglik # Log-likelihood of the alternative solution
Calculate upper bound for the joint spectral radius of the "companion form AR matrices" of the regimes
Description
bound_JSR
calculates an bounds for the joint spectral radius of the
"companion form AR matrices" matrices of the regimes to assess the validity of the stationarity condition.
Usage
bound_JSR(
stvar,
epsilon = 0.02,
adaptive_eps = FALSE,
ncores = 2,
print_progress = TRUE
)
Arguments
stvar |
object of class |
epsilon |
a strictly positive real number that approximately defines the goal of length of the interval between the lower
and upper bounds. A smaller epsilon value results in a narrower interval, thus providing better accuracy for the bounds,
but at the cost of increased computational effort. Note that the bounds are always wider than |
adaptive_eps |
logical: if |
ncores |
the number of cores to be used in parallel computing. |
print_progress |
logical: should the progress of the algorithm be printed? |
Details
A sufficient condition for ergodic stationarity of the STVAR processes implemented in sstvars
is that the joint
spectral radius of the "companion form AR matrices" of the regimes is smaller than one (Kheifets and Saikkonen, 2020).
This function calculates an upper (and lower) bound for the JSR and is implemented to assess the validity of this condition
in practice. If the bound is smaller than one, the model is deemed ergodic stationary.
Implements the branch-and-bound method by Gripenberg (1996) in the conventional form (adaptive_eps=FALSE
) and in a form
incorporating "adaptive tightness" (adaptive_eps=FALSE
). The latter approach is unconventional and does not guarantee
appropriate convergence of the bounds close to the desired tightness given in the argument epsilon
, but it usually
substantially speeds up the algorithm. When print_progress==TRUE
, the tightest bounds found so-far are printed in each
iteration of the algorithm, so you can also just terminate the algorithm when the bounds are tight enough for your purposes.
Consider also adjusting the argument epsilon
, in particular when adaptive_eps=FALSE
, as larger epsilon does not
just make the bounds less tight but also speeds up the algorithm significantly. See Chang and Blondel (2013) for a discussion
on variuous methods for bounding the JSR.
Value
Returns lower and upper bounds for the joint spectral radius of the "companion form AR matrices" of the regimes.
References
C-T Chang and V.D. Blondel. 2013 . An experimental study of approximation algorithms for the joint spectral radius. Numerical algorithms, 64, 181-202.
Gripenberg, G. 1996. Computing the joint spectral radius. Linear Algebra and its Applications, 234, 43–60.
I.L. Kheifets, P.J. Saikkonen. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
Examples
## Below examples take approximately 5 seconds to run.
# Gaussian STVAR p=1, M=2 model with weighted relative stationary densities
# of the regimes as the transition weight function:
theta_122relg <- c(0.734054, 0.225598, 0.705744, 0.187897, 0.259626, -0.000863,
-0.3124, 0.505251, 0.298483, 0.030096, -0.176925, 0.838898, 0.310863, 0.007512,
0.018244, 0.949533, -0.016941, 0.121403, 0.573269)
mod122 <- STVAR(data=gdpdef, p=1, M=2, params=theta_122relg)
# Absolute values of the eigenvalues of the "companion form AR matrices":
summary(mod122)$abs_boldA_eigens
# It is a necessary (but not sufficient!) condition for ergodic stationary that
# the spectral radius of the "companion form AR matrices" are smaller than one
# for all of the regimes. A sufficient (but not necessary) condition for
# ergodic stationary is that the joint spectral radius of the companion form
# AR matrices" of the regimes is smaller than one. Therefore, we calculate
# bounds for the joint spectral radius.
## Bounds by Gripenberg's (1996) branch-and-bound method:
# Since the largest modulus of the companion form AR matrices is not very close
# to one, we likely won't need very thight bounds to verify the JSR is smaller
# than one. Thus, using a small epsilon would make the algorithm unnecessarily slow,
# so we use the (still quite small) epsilon=0.01:
bound_JSR(mod122, epsilon=0.01, adaptive_eps=FALSE)
# The upper bound is smaller than one, so the model is ergodic stationary.
# If we want tighter bounds, we can set smaller epsilon, e.g., epsilon=0.001:
bound_JSR(mod122, epsilon=0.001, adaptive_eps=FALSE)
# Using adaptive_eps=TRUE usually speeds up the algorithm when the model
# is large, but with the small model here, the speed-difference is small:
bound_JSR(mod122, epsilon=0.001, adaptive_eps=TRUE)
Calculate upper bound for the joint spectral radius of a set of matrices
Description
bound_jsr_G
calculates lower and upper bounds for the joint spectral radious of a set of square matrices,
typically the "bold A" matrices, using the algorithm by Gripenberg (1996).
Usage
bound_jsr_G(
S,
epsilon = 0.01,
adaptive_eps = FALSE,
ncores = 2,
print_progress = TRUE
)
Arguments
S |
the set of matrices the bounds should be calculated for in an array, in STVAR applications,
all |
epsilon |
a strictly positive real number that approximately defines the goal of length of the interval between the lower
and upper bounds. A smaller epsilon value results in a narrower interval, thus providing better accuracy for the bounds,
but at the cost of increased computational effort. Note that the bounds are always wider than |
adaptive_eps |
logical: if |
ncores |
the number of cores to be used in parallel computing. |
print_progress |
logical: should the progress of the algorithm be printed? |
Details
The upper and lower bounds are calculated using the Gripenberg's (1996) branch-and-bound method, which is also discussed
in Chang and Blondel (2013). This function can be generally used for approximating the JSR of a set of square matrices, but the
main intention is STVAR applications (for models created with sstvars
, the function bound_JSR
should be preferred).
Specifically, Kheifets and Saikkonen (2020) show that if the joint spectral radius of the companion form AR matrices of the regimes
is smaller than one, the STVAR process is ergodic stationary. Virolainen (2025) shows the same result for his parametrization of
of threshold and smooth transition vector autoregressive models. Therefore, if the upper bound is smaller than one, the process is
stationary ergodic. However, as the condition is not necessary but sufficient and also because the bound might be too conservative,
upper bound larger than one does not imply that the process is not ergodic stationary. You can try higher accuracy, and if the bound
is still larger than one, the result does not tell whether the process is ergodic stationary or not.
Note that with high precision (small epsilon
), the computational effort required are substantial and
the estimation may take long, even though the function takes use of parallel computing. This is because
with small epsilon the the number of candidate solutions in each iteration may grow exponentially and a large
number of iterations may be required. For this reason, adaptive_eps=TRUE
can be considered for large matrices,
in which case the algorithm starts with a large epsilon, and then decreases it when new candidate solutions are
not found, until the epsilon given by the argument epsilon
is reached.
Value
Returns an upper bound for the joint spectral radius of the "companion form AR matrices" of the regimes.
References
C-T Chang and V.D. Blondel. 2013 . An experimental study of approximation algorithms for the joint spectral radius. Numerical algorithms, 64, 181-202.
Gripenberg, G. 1996. Computing the joint spectral radius. Linear Algebra and its Applications, 234, 43–60.
I.L. Kheifets, P.J. Saikkonen. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
Examples
## Below examples take approximately 5 seconds to run.
# A set of two (5x5) square matrices:
set.seed(1); S1 <- array(rnorm(20*20*2), dim=c(5, 5, 2))
# Bound the joint spectral radius of the set of matrices S1, with the
# approximate tightness epsilon=0.01:
bound_jsr_G(S1, epsilon=0.01, adaptive_eps=FALSE)
# Obtain bounds faster with adaptive_eps=TRUE:
bound_jsr_G(S1, epsilon=0.01, adaptive_eps=TRUE)
# Note that the upper bound is not the same as with adaptive_eps=FALSE.
# A set of three (3x3) square matrices:
set.seed(2); S2 <- array(rnorm(3*3*3), dim=c(3, 3, 3))
# Bound the joint spectral radius of the set of matrices S2:
bound_jsr_G(S2, epsilon=0.01, adaptive_eps=FALSE)
# Larger epsilon terminates the iteration earlier and results in wider bounds:
bound_jsr_G(S2, epsilon=0.05, adaptive_eps=FALSE)
# A set of eight (2x2) square matrices:
set.seed(3); S3 <- array(rnorm(2*2*8), dim=c(2, 2, 8))
# Bound the joint spectral radius of the set of matrices S3:
bound_jsr_G(S3, epsilon=0.01, adaptive_eps=FALSE)
Compute the bounding constant for acceptance-rejection sampling
Description
bounding_const_M
calculates the bounding constant M
used in the acceptance-rejection sampling algorithm
for the univariate skewed t-distribution described in Hansen (1994)
Usage
bounding_const_M(nu, lambda)
Arguments
nu |
the degrees of freedom parameter value, a numeric scalar strictly larger than two. |
lambda |
the skewness parameter value, a numeric scalar strictly between -1 and 1. |
Details
The function computes the bounding constant M
required for the acceptance-rejection sampling method by evaluating
the ratio of the skewed t-density (skewed_t_dens
) to the standard t-density (stand_t_dens
)
over a grid of y
values ranging from -10
to 10
. To improve the efficiency of the sampling algorithm, the degrees
of freedom parameter for the proposal distribution is set to the minimum of nu
and 3
, ensuring heavier tails in the
proposal distribution when nu
is large. A safety margin of 10% is added to the maximum ratio to account for numerical
inaccuracies and ensure that the inequality f(y) \leq M \cdot q(y)
holds over the entire support.
Value
Returns a numeric scalar representing the estimated bounding constant M
to be used in the acceptance-rejection
sampling algorithm.
References
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Calculate gradient or Hessian matrix
Description
calc_gradient
or calc_hessian
calculates the gradient or Hessian matrix
of the given function at the given point using central difference numerical approximation.
get_gradient
or get_hessian
calculates the gradient or Hessian matrix of the
log-likelihood function at the parameter estimates of a class 'stvar'
object. get_soc
returns eigenvalues of the Hessian matrix, and get_foc
is the same as get_gradient
but named conveniently.
Usage
calc_gradient(x, fn, h = 0.001, ...)
calc_hessian(x, fn, h = 0.001, ...)
get_gradient(stvar, ...)
get_hessian(stvar, ...)
get_foc(stvar, ...)
get_soc(stvar, ...)
Arguments
x |
a numeric vector specifying the point where the gradient or Hessian should be calculated. |
fn |
a function that takes in argument |
h |
difference used to approximate the derivatives: either a positive real number of a vector of
positive real numbers with the same length as |
... |
other arguments passed to |
stvar |
object of class |
Details
In particular, the functions get_foc
and get_soc
can be used to check whether
the found estimates denote a (local) maximum point, a saddle point, or something else. Note that
profile log-likelihood functions can be conveniently plotted with the function profile_logliks
.
Value
Gradient functions return numerical approximation of the gradient and Hessian functions return
numerical approximation of the Hessian. get_soc
returns eigenvalues of the Hessian matrix.
Warning
No argument checks!
Examples
# Create a simple function:
foo <- function(x) x^2 + x
# Calculate the gradient at x=1 and x=-0.5:
calc_gradient(x=1, fn=foo)
calc_gradient(x=-0.5, fn=foo)
# Create a more complicated function
foo <- function(x, a, b) a*x[1]^2 - b*x[2]^2
# Calculate the gradient at x=c(1, 2) with parameter values a=0.3 and b=0.1:
calc_gradient(x=c(1, 2), fn=foo, a=0.3, b=0.1)
# Create a linear Gaussian VAR p=1 model:
theta_112 <- c(0.649526, 0.066507, 0.288526, 0.021767, -0.144024, 0.897103,
0.601786, -0.002945, 0.067224)
mod112 <- STVAR(data=gdpdef, p=1, M=1, params=theta_112)
# Calculate the gradient of the log-likelihood function about the parameter values:
get_foc(mod112)
# Calculate the eigenvalues of the Hessian matrix of the log-likelihood function
# about the parameter values:
get_soc(mod112)
Simulate counterfactual forecast scenarios for structural STVAR models.
Description
cfact_fore
simulates counterfactual forecast scenarios for structural STVAR models.
Usage
cfact_fore(
stvar,
nsteps,
nsim = 1000,
pi = 0.95,
pred_type = c("mean", "median"),
exo_weights = NULL,
cfact_type = c("fixed_path", "muted_response"),
policy_var = 1,
mute_var = NULL,
cfact_start = 1,
cfact_end = 1,
cfact_path = NULL
)
## S3 method for class 'cfactfore'
plot(x, ..., nt, trans_weights = TRUE)
## S3 method for class 'cfactfore'
print(x, ..., digits = 3)
Arguments
stvar |
an object of class |
nsteps |
how many steps ahead should be predicted, i.e., the forecast horizon? |
nsim |
to how many independent simulations should the forecast be based on? |
pi |
a numeric vector specifying the confidence levels of the prediction intervals. |
pred_type |
should the pointforecast be based on sample "median" or "mean"? |
exo_weights |
if |
cfact_type |
a character string indicating the type of counterfactual to be computed: should the path of the policy
variable be fixed to some hypothetical path ( |
policy_var |
a positive integer between |
mute_var |
a positive integer between |
cfact_start |
a positive integer between |
cfact_end |
a positive integer between |
cfact_path |
a numeric vector of length |
x |
object of class |
... |
parameters passed to |
nt |
a positive integer specifying the number of observations to be plotted along with the forecast. |
trans_weights |
should forecasts for transition weights be plotted? |
digits |
how many significant digits to print? |
Details
Two types of counterfactual forecast scenarios are accommodated where in given forecast horizons
either (1) the policy variable of interest takes some hypothetical path (cfact_type="fixed_path"
), or (2)
its responses to lagged and contemporaneous movements of some given variable are shut off (cfact_type="muted_response"
).
In both cases, the counterfactual scenarios are simulated by creating hypothetical shocks to the policy variable of interest
that yield the counterfactual outcome. This approach has the appealing feature that the counterfactual deviations from the
policy reaction function are treated as policy surprises, allowing them to propagate normally, so that the dynamics of the model
are not, per se, tampered but just the policy surprises are.
Important: This function assumes that when the policy variable of interest is the i_1
th variable, the shock
to it that is manipulated is the i_1
th shock. This should be automatically satisfied for recursively identified models,
whereas for model identified by heteroskedasticity or non-Gaussianity, the ordering of the shocks can be generally changed
without loss of generality with the function reorder_B_columns
. In Type (2) counterfactuals it is additionally assumed
that, if the variable to whose movements the policy variable should not react to is the i_2
th variable, the shock to it
is the i_2
th shock. If it is not clear whether the i_2
th shock can be interpreted as a shock to a variable
(but has a broader definition such as "a demand shock"), the Type (2) counterfactual scenario is interpreted as follows: the i_1
th
variable does not react to lagged movements of the i_2
th variable nor to the i_2
th shock.
See the seminal paper of Bernanke et al (1997) for discussing about the "Type (1)" counterfactuals and Kilian and Lewis (2011) for discussion about the "Type (2)" counterfactuals. See Kilian and Lütkepohl (2017), Section 4.4 for further discussion about counterfactual forecast scenarios. The literature cited about considers linear models, but it is explained in the vignette of this package how this function computes the counterfactual forecast scenarios for the STVAR models in a way that accommodates nonlinear time-varying dynamics.
Value
Returns a class 'cfactfore'
list with the following elements:
- $cfact_pred
Counterfactual forecast in a class '
stvarpred
' object (see?predict.stvar
).- $pred
Forecast that does not impose the counterfactual scenario, in a class '
stvarpred
' object.- stvar
The original STVAR model object.
- input
A list containing the arguments used to calculate the counterfactual.
Returns the input object x
invisibly.
Functions
-
plot(cfactfore)
: plot method -
print(cfactfore)
: print method
References
Bernanke B., Gertler M., Watson M. 1997. Systematic monetary policy and the effects of oilprice shocks. Brookings Papers on Economic Activity, 1, 91—142.
Kilian L., Lewis L. 2011. Does the fed respond to oil price shocks? The Economic Journal, 121:555.
Kilian L., Lütkepohl H. 2017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
See Also
GIRF
, GFEVD
, linear_IRF
, hist_decomp
, cfact_hist
,
cfact_girf
, fitSSTVAR
Examples
# Recursively identified logistic Student's t STVAR(p=3, M=2) model with the first
# lag of the second variable as the switching variable:
params32logt <- c(0.5959, 0.0447, 2.6279, 0.2897, 0.2837, 0.0504, -0.2188, 0.4008,
0.3128, 0.0271, -0.1194, 0.1559, -0.0972, 0.0082, -0.1118, 0.2391, 0.164, -0.0363,
-1.073, 0.6759, 3e-04, 0.0069, 0.4271, 0.0533, -0.0498, 0.0355, -0.4686, 0.0812,
0.3368, 0.0035, 0.0325, 1.2289, -0.047, 0.1666, 1.2067, 7.2392, 11.6091)
mod32logt <- STVAR(gdpdef, p=3, M=2, params=params32logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="recursive")
# Counteractual forecast scenario 5 steps ahead (using only 100 Monte Carlo repetitions
# to save computation time), where the first variable takes values 1, -2, and 3 in the
# horizons 1, 2, and 3, respectively:
set.seed(1)
cfact1 <- cfact_fore(mod32logt, nsteps=5, nsim=100, cfact_type="fixed_path", policy_var=1,
cfact_start=1, cfact_end=3, cfact_path=c(1, -2, 3))
cfact1 # Print the results
plot(cfact1) # Plot the factual and counterfactual forecasts
# Counteractual forecast scenario 5 steps ahead (using only 100 Monte Carlo repetitions
# to save computation time), where the first variable does not respond to lagged
# movements of the second variable nor to the second shock in time periods from 1 to 3:
set.seed(1)
cfact2 <- cfact_fore(mod32logt, nsteps=5, nsim=100, cfact_type="muted_response", policy_var=1,
mute_var=2, cfact_start=1, cfact_end=3)
cfact2 # Print the results
plot(cfact2) # Plot the factual and counterfactual forecasts
Simulate counterfactual generalized impulse response functions for structural STVAR models.
Description
cfact_girf
simulates counterfactual generalized impulse response functions for structural STVAR models.
Usage
cfact_girf(
stvar,
which_shocks,
shock_size = 1,
N = 30,
R1 = 200,
R2 = 250,
init_regime = 1,
init_values = NULL,
which_cumulative = numeric(0),
scale = NULL,
scale_type = c("instant", "peak"),
scale_horizon = N,
ci = c(0.95, 0.8),
use_data_shocks = FALSE,
data_girf_pars = c(0, 0.75, 0, 0, 1.5),
ncores = 2,
burn_in = 1000,
exo_weights = NULL,
seeds = NULL,
use_parallel = TRUE,
cfact_type = c("fixed_path", "muted_response"),
policy_var = 1,
mute_var = NULL,
cfact_start = 1,
cfact_end = 1,
cfact_path = NULL
)
## S3 method for class 'cfactgirf'
plot(x, ...)
## S3 method for class 'cfactgirf'
print(x, ..., digits = 3)
Arguments
stvar |
an object of class |
which_shocks |
a numeric vector of length at most |
shock_size |
a non-zero scalar value specifying the common size for all scalar components of the structural shock. Note that the conditional covariance matrix of the structural shock is normalized to an identity matrix and that the (generalized) impulse responses may not be symmetric with respect to the sign and size of the shock. |
N |
a positive integer specifying the horizon how far ahead should the generalized impulse responses be calculated. |
R1 |
the number of repetitions used to estimate GIRF for each initial value. |
R2 |
the number of initial values to use, i.e., to draw from |
init_regime |
an integer in |
init_values |
a size |
which_cumulative |
a numeric vector with values in |
scale |
should the GIRFs to some of the shocks be scaled so that they
correspond to a specific magnitude of instantaneous or peak response
of some specific variable (see the argument |
scale_type |
If argument |
scale_horizon |
If |
ci |
a numeric vector with elements in |
use_data_shocks |
set |
data_girf_pars |
a length five numeric vector with the following elements determining settings for
|
ncores |
the number CPU cores to be used in parallel computing. Only single core computing is supported if an initial value is specified (and the GIRF won't thus be estimated multiple times). |
burn_in |
Burn-in period for simulating initial values from a regime. |
exo_weights |
if |
seeds |
A numeric vector initializing the seeds for the random number generator for estimation of each GIRF. Should have the length of at least (extra seeds are removed from the end of the vector)...
Set |
use_parallel |
employ parallel computing? If |
cfact_type |
a character string indicating the type of counterfactual to be computed: should the path of the policy
variable be fixed to some hypothetical path ( |
policy_var |
a positive integer between |
mute_var |
a positive integer between |
cfact_start |
a positive integer between |
cfact_end |
a positive integer between |
cfact_path |
a numeric vector of length |
x |
object of class |
... |
parameters passed to |
digits |
how many significant digits to print? |
Details
Two types of counterfactual generalized impulse response functions (GIRFs) are accommodated where in given impulse response
horizons either (1) the policy variable of interest takes some hypothetical path (cfact_type="fixed_path"
), or (2)
its responses to lagged and contemporaneous movements of some given variable are shut off (cfact_type="muted_response"
).
In both cases, the counterfactual scenarios are simulated by creating hypothetical shocks to the policy variable of interest
that yield the counterfactual outcome. This approach has the appealing feature that the counterfactual deviations from the
policy reaction function are treated as policy surprises, allowing them to propagate normally, so that the dynamics of the model
are not, per se, tampered but just the policy surprises are.
Important: This function assumes that when the policy variable of interest is the i_1
th variable, the shock
to it that is manipulated is the i_1
th shock. This should be automatically satisfied for recursively identified models,
whereas for model identified by heteroskedasticity or non-Gaussianity, the ordering of the shocks can be generally changed
without loss of generality with the function reorder_B_columns
. In Type (2) counterfactuals it is additionally assumed
that, if the variable to whose movements the policy variable should not react to is the i_2
th variable, the shock to it
is the i_2
th shock. If it is not clear whether the i_2
th shock can be interpreted as a shock to a variable
(but has a broader definition such as "a demand shock"), the Type (2) counterfactual scenario is interpreted as follows: the i_1
th
variable does not react to lagged movements of the i_2
th variable nor to the i_2
th shock.
See the seminal paper of Bernanke et al (1997) for discussing about the "Type (1)" counterfactuals and Kilian and Lewis (2011) for discussion about the "Type (2)" counterfactuals. See Kilian and Lütkepohl (2017), Section 4.5 for further discussion about counterfactuals. The literature cited about considers linear models, but it is explained in the vignette of this package how this function computes the historical counterfactuals for the STVAR models in a way that accommodates nonlinear time-varying dynamics.
Value
Returns a class 'cfactgirf'
list with the following elements:
$girf
An object of class
'girf'
containing the counterfactual GIRFs (see?GIRF
).$stvar
The original STVAR model object.
$input
A list containing the arguments used to calculate the counterfactual.
Returns the input object x
invisibly.
Functions
-
plot(cfactgirf)
: plot method -
print(cfactgirf)
: print method
References
Bernanke B., Gertler M., Watson M. 1997. Systematic monetary policy and the effects of oilprice shocks. Brookings Papers on Economic Activity, 1, 91—142.
Kilian L., Lewis L. 2011. Does the fed respond to oil price shocks? The Economic Journal, 121:555.
Kilian L., Lütkepohl H. 2017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
See Also
GIRF
, GFEVD
, linear_IRF
, hist_decomp
, cfact_hist
,
cfact_fore
, fitSSTVAR
Examples
# Recursively identified logistic Student's t STVAR(p=3, M=2) model with the first
# lag of the second variable as the switching variable:
params32logt <- c(0.5959, 0.0447, 2.6279, 0.2897, 0.2837, 0.0504, -0.2188, 0.4008,
0.3128, 0.0271, -0.1194, 0.1559, -0.0972, 0.0082, -0.1118, 0.2391, 0.164, -0.0363,
-1.073, 0.6759, 3e-04, 0.0069, 0.4271, 0.0533, -0.0498, 0.0355, -0.4686, 0.0812,
0.3368, 0.0035, 0.0325, 1.2289, -0.047, 0.1666, 1.2067, 7.2392, 11.6091)
mod32logt <- STVAR(gdpdef, p=3, M=2, params=params32logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="recursive")
# Counterfactual GIRFs for Shock 2 with horizon N=5 (using only R1=R2=10 Monte Carlo repetitions
# to save computation time), where the first variable takes values 1, -2, and 3 in the
# horizons 1, 2, and 3, respectively:
cfact1 <- cfact_girf(mod32logt, which_shocks=2, N=5, R1=10, R2=10, init_regime=1, seeds=1:10,
cfact_type="fixed_path", policy_var=1, cfact_start=1, cfact_end=3, cfact_path=c(1, -2, 3))
cfact1 # Print the results
plot(cfact1) # Plot the counterfactual GIRF
# Counterfactual GIRFs for Shock 2 with horizon N=5 (using only R1=R2=10 Monte Carlo repetitions
# to save computation time), where the first variable does not respond to lagged movements
# of the second variable nor to the second shock in time periods from 1 to 3:
cfact2 <- cfact_girf(mod32logt, which_shocks=2, N=5, R1=10, R2=10, init_regime=1, seeds=1:20,
cfact_type="muted_response", policy_var=1, mute_var=2, cfact_start=1, cfact_end=3)
cfact2 # Print the results
plot(cfact2) # Plot the counterfactual GIRF
Simulate historical counterfactual for structural STVAR models.
Description
cfact_hist
simulates historical counterfactual for structural STVAR models.
Usage
cfact_hist(
stvar,
cfact_type = c("fixed_path", "muted_response"),
policy_var = 1,
mute_var = NULL,
cfact_start = 1,
cfact_end = 1,
cfact_path = NULL
)
## S3 method for class 'cfacthist'
plot(x, ...)
## S3 method for class 'cfacthist'
print(x, ..., digits = 3)
Arguments
stvar |
an object of class |
cfact_type |
a character string indicating the type of counterfactual to be computed: should the path of the policy
variable be fixed to some hypothetical path ( |
policy_var |
a positive integer between |
mute_var |
a positive integer between |
cfact_start |
a positive integer between |
cfact_end |
a positive integer between |
cfact_path |
a numeric vector of length |
x |
object of class |
... |
arguments passed to the function |
digits |
how many significant digits to print? |
Details
Two types of historical counterfactuals are accommodated where in given historical points of time
either (1) the policy variable of interest takes some hypothetical path (cfact_type="fixed_path"
), or (2)
its responses to lagged and contemporaneous movements of some given variable are shut off (cfact_type="muted_response"
).
In both cases, the counterfactual scenarios are simulated by creating hypothetical shocks to the policy variable of interest
that yield the counterfactual outcome. This approach has the appealing feature that the counterfactual deviations from the
policy reaction function are treated as policy surprises, allowing them to propagate normally, so that the dynamics of the model
are not, per se, tampered but just the policy surprises are.
Important: This function assumes that when the policy variable of interest is the i_1
th variable, the shock
to it that is manipulated is the i_1
th shock. This should be automatically satisfied for recursively identified models,
whereas for model identified by heteroskedasticity or non-Gaussianity, the ordering of the shocks can be generally changed
without loss of generality with the function reorder_B_columns
. In Type (2) counterfactuals it is additionally assumed
that, if the variable to whose movements the policy variable should not react to is the i_2
th variable, the shock to it
is the i_2
th shock. If it is not clear whether the i_2
th shock can be interpreted as a shock to a variable
(but has a broader definition such as "a demand shock"), the Type (2) counterfactual scenario is interpreted as follows: the i_1
th
variable does not react to lagged movements of the i_2
th variable nor to the i_2
th shock.
See the seminal paper of Bernanke et al (1997) for discussing about the "Type (1)" counterfactuals and Kilian and Lewis (2011) for discussion about the "Type (2)" counterfactuals. See Kilian and Lütkepohl (2017), Section 4.5 for further discussion about the historical counterfactuals. The literature cited about considers linear models, but it is explained in the vignette of this package how this function computes the historical counterfactuals for the STVAR models in a way that accommodates nonlinear time-varying dynamics.
Value
Returns a class 'cfacthist'
list with the following elements:
- cfact_data
A matrix of size
(T+p \times d)
containing the counterfactual time series. Note that the firstp
rows are for the initial values prior the time periodt=1
.- cfact_shocks
A matrix of size
(T \times d)
containing the counterfactual shocks.- cfact_weights
A matrix of size
(T \times M)
containing the counterfactual transition weights.- stvar
The original STVAR model object.
- input
A list containing the arguments used to calculate the counterfactual.
Returns the input object x
invisibly.
Functions
-
plot(cfacthist)
: plot method -
print(cfacthist)
: print method
References
Bernanke B., Gertler M., Watson M. 1997. Systematic monetary policy and the effects of oilprice shocks. Brookings Papers on Economic Activity, 1, 91—142.
Kilian L., Lewis L. 2011. Does the fed respond to oil price shocks? The Economic Journal, 121:555.
Kilian L., Lütkepohl H. 2017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
See Also
GIRF
, GFEVD
, linear_IRF
, hist_decomp
, cfact_fore
,
cfact_girf
, fitSSTVAR
Examples
# Recursively identified logistic Student's t STVAR(p=3, M=2) model with the first
# lag of the second variable as the switching variable:
params32logt <- c(0.5959, 0.0447, 2.6279, 0.2897, 0.2837, 0.0504, -0.2188, 0.4008,
0.3128, 0.0271, -0.1194, 0.1559, -0.0972, 0.0082, -0.1118, 0.2391, 0.164, -0.0363,
-1.073, 0.6759, 3e-04, 0.0069, 0.4271, 0.0533, -0.0498, 0.0355, -0.4686, 0.0812,
0.3368, 0.0035, 0.0325, 1.2289, -0.047, 0.1666, 1.2067, 7.2392, 11.6091)
mod32logt <- STVAR(gdpdef, p=3, M=2, params=params32logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="recursive")
# Simulate historical counterfactual where the first variable takes the values 5 and -5
# in the first and second time periods, respectively.
cfact1 <- cfact_hist(mod32logt, cfact_type="fixed_path", policy_var=1, cfact_start=1,
cfact_end=2, cfact_path=c(5, -5))
print(cfact1, start=c(1959, 1), end=c(1960, 4)) # Print cfact data from 1959Q1 to 1960Q4
plot(cfact1) # Plot the observed and counterfactual data
# Simulate historical counterfactual where the first variable does not respond to lagged
# movements of the second variable nor to the second shock in time periods from 10 to 100.
cfact2 <- cfact_hist(mod32logt, cfact_type="muted_response", policy_var=1, mute_var=2,
cfact_start=10, cfact_end=100)
print(cfact2, start=c(1960, 4), end=c(1963, 4)) # Print cfact data from 1960Q4 to 1963Q4
plot(cfact2) # plot the observed and counterfactual data
Change parametrization of a parameter vector
Description
change_parametrization
changes the parametrization of the given parameter
vector to change_to
.
Usage
change_parametrization(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
change_to = c("intercept", "mean", "orig", "alt")
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
change_to |
|
Details
Parametrization cannot be changed for models with mean constraints! Note that changing between "orig" and "alt"
changes the meaning of sign constraints in B_constraints
(sign constraints imposed on "alt" is very different to
those imposed on "orig"). Thus, this function should not be used to switch between "orig" and "alt" when sign constraints
are imposed!
Value
Returns parameter vector described in params
, but with parametrization changed according
to change_to
.
Warning
No argument checks!
Change the parameters of a specific regime of the given parameter vector
Description
change_regime
changes the regime parameters
(\phi_{m},vec(A_{m,1}),...,\vec(A_{m,p}),vech(\Omega_m))
(replace vech(\Omega_m)
by vec(B_m)
for cond_dist="ind_Student"
)
of the given regime to the new given parameters.
Usage
change_regime(
p,
M,
d,
params,
m,
regime_pars,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t")
)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
m |
which regime? |
regime_pars |
|
Details
Does not support constrained models or structural models. Weight parameters and distribution parameters are not changed.
Value
Returns parameter vector with m
:th regime changed to regime_pars
.
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Check Matrix B Invertibility with C++ (Internal Function)
Description
This internal function takes a cube of matrices (all_Omegas
),
a matrix of weights (alpha_mt
), and a numerical tolerance (posdef_tol
)
to check the invertibility of weighted sums of the matrices in the cube. For each row
in alpha_mt
, it computes a weighted sum of matrices, and checks if this sum is
invertible by verifying that its determinant is not within the specified tolerance of zero.
Usage
check_Bt_Cpp(all_Omegas, alpha_mt, posdef_tol)
Arguments
all_Omegas |
A cube (3D array) of impact matrices, with each slice being an inveritble square matrix. |
alpha_mt |
A matrix of weights, with as many columns as there are slices in |
posdef_tol |
A strictly positive small number used as a tolerance for checking the invertibility of the matrix. The matrix is considered non-invertible if its determinant is less than this tolerance. |
Value
A boolean value: 'TRUE' if all weighted sums are invertible up to the specified tolerance, 'FALSE' otherwise.
Check the constraint matrix has the correct form
Description
check_constraints
checks that the constraints are correctly set.
Usage
check_constraints(
data,
p,
M,
d,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
Value
Does return anything but checks the constraints and throws an error if something is wrong.
Check the data is in the correct form
Description
check_data
checks the data.
Usage
check_data(data, p)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
Value
Checks the data and tries to correct it. Throws an error if something is wrong and returns the corrected data otherwise.
Checks whether the given exogenous transition weights for simulation are correctly specified.
Description
check_exoweights
checks whether the given exogenous transition weights for
simulation are correctly specified.
Usage
check_exoweights(M, exo_weights, how_many_rows, name_of_row_number)
Arguments
exo_weights |
Exogenous transition weights weights given for simulation in some context. |
how_many_rows |
how many rows the exogenous weights should have? |
name_of_row_number |
what is the name of the object whose value should determine the the number of rows in the exogenous weights? |
Details
Used by simulate.stvar, predict.stvar, GIRF, and GFEVD.
Value
Throws an error if the exogenous weights are incorrectly specified.
Check that p, M, and d are correctly set
Description
check_pMd
checks the arguments p, M, and d.
Usage
check_pMd(
p,
M,
d,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity")
)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
Value
Throws an error if something is wrong.
Check whether the parameter vector is in the parameter space and throw error if not
Description
check_params
checks whether the parameter vector is in the parameter
space.
Usage
check_params(
data,
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
transition_weights,
allow_unstab = FALSE,
stab_tol = 0.001,
posdef_tol = 1e-08,
distpar_tol = 1e-08,
weightpar_tol = 1e-08
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
transition_weights |
(optional; only for models with |
allow_unstab |
If |
stab_tol |
numerical tolerance for stability of condition of the regimes: if the "bold A" matrix of any regime
has eigenvalues larger that |
posdef_tol |
numerical tolerance for positive definiteness of the error term covariance matrices: if the error term covariance matrix of any regime has eigenvalues smaller than this, the parameter is considered to be outside the parameter space. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error. |
distpar_tol |
the parameter vector is considered to be outside the parameter space if the degrees of
freedom parameters is not larger than |
weightpar_tol |
numerical tolerance for weight parameters being in the parameter space. Values closer to to the border of the parameter space than this are considered to be "outside" the parameter space. |
Value
Throws an informative error if there is something wrong with the parameter vector.
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Examples
# There examples will cause an informative error
params112_notpd <- c(6.5e-01, 7.0e-01, 2.9e-01, 2.0e-02, -1.4e-01,
9.0e-01, 6.0e-01, -1.0e-02, 1.0e-07)
try(check_params(p=1, M=1, d=2, params=params112_notpd))
params112_notstat <- c(6.5e-01, 7.0e-01, 10.9e-01, 2.0e-02, -1.4e-01,
9.0e-01, 6.0e-01, -1.0e-02, 1.0e-07)
try(check_params(p=1, M=1, d=2, params=params112_notstat))
params112_wronglength <- c(6.5e-01, 7.0e-01, 2.9e-01, 2.0e-02, -1.4e-01,
9.0e-01, 6.0e-01, -1.0e-02)
try(check_params(p=1, M=1, d=2, params=params112_wronglength))
Checks whether the given object has class attribute 'stvar'
Description
check_stvar
checks that the object has class attribute 'stvar'.
Usage
check_stvar(object, object_name)
Arguments
object |
S3 object to be tested |
object_name |
what is the name of the object that should of class 'stvar'? |
Value
Throws an error if the object doesn't have the class attribute 'stvar'.
Check the argument weightfun_pars
Description
check_weightfun_pars
checks that the argument weightfun_pars
.
is correctly set, if not, tries to correct them.
Usage
check_weightfun_pars(
data,
p,
M,
d,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t")
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
Value
Does checks the argument weightfun_pars
and throws an error if something is wrong; returns
a corrected version of the argument if possible.
Create Matrix F_i
Description
create_Fi_matrix
function generates a (T_obs \times T_obs)
matrix
with 1's on the (i+1)
-th sub-diagonal and 0's elsewhere.
Usage
create_Fi_matrix(i, T_obs)
Arguments
i |
Integer, the lag for which the matrix is constructed, corresponding to the sub-diagonal filled with 1's. |
T_obs |
Integer, the number of time periods or observations in the dataset, corresponding to the dimensions of the matrix. |
Details
Used in Portmanteau_test
. The matrix F_i
in Lütkepohl (2005), p.158.
Value
A (T_obs \times T_obs)
matrix with 1's on the (i+1)
-th sub-diagonal and 0's elsewhere.
References
Lütkepohl, H. (2005). New Introduction to Multiple Time Series Analysis. Springer.
Create a special matrix J
Description
create_J_matrix
generates a d x dp matrix J, where the first d x d block is the identity matrix I_d,
and the rest is filled with zeros.
Usage
create_J_matrix(d, p)
Arguments
d |
An integer representing the dimension of the identity matrix. |
p |
An integer representing the factor by which to extend the matrix with zeros. |
Value
A d x dp
matrix J
where the first d x d
block is the identity matrix I_d
,
and the rest is filled with zeros.
Simultaneously diagonalize two covariance matrices
Description
diag_Omegas
Simultaneously diagonalizes two covariance matrices using
eigenvalue decomposition.
Usage
diag_Omegas(Omega1, Omega2)
Arguments
Omega1 |
a positive definite |
Omega2 |
another positive definite |
Details
See the return value and Muirhead (1982), Theorem A9.9 for details.
Value
Returns a length d^2 + d
vector where the first d^2
elements
are vec(W)
with the columns of W
being (specific) eigenvectors of
the matrix \Omega_2\Omega_1^{-1}
and the rest d
elements are the
corresponding eigenvalues "lambdas". The result satisfies WW' = Omega1
and
Wdiag(lambdas)W' = Omega2
.
If Omega2
is not supplied, returns a vectorized symmetric (and pos. def.)
square root matrix of Omega1
.
Warning
No argument checks! Does not work with dimension d=1
!
References
Muirhead R.J. 1982. Aspects of Multivariate Statistical Theory, Wiley.
Examples
# Create two (2x2) coviance matrices using the parameters W and lambdas:
d <- 2 # The dimension
W0 <- matrix(1:(d^2), nrow=2) # W
lambdas0 <- 1:d # The eigenvalues
(Omg1 <- W0%*%t(W0)) # The first covariance matrix
(Omg2 <- W0%*%diag(lambdas0)%*%t(W0)) # The second covariance matrix
# Then simultaneously diagonalize the covariance matrices:
res <- diag_Omegas(Omg1, Omg2)
# Recover W:
W <- matrix(res[1:(d^2)], nrow=d, byrow=FALSE)
tcrossprod(W) # == Omg1, the first covariance matrix
# Recover lambdas:
lambdas <- res[(d^2 + 1):(d^2 + d)]
W%*%diag(lambdas)%*%t(W) # == Omg2, the second covariance matrix
Residual diagnostic plot for a STVAR model
Description
diagnostic_plot
plots a multivariate residual diagnostic plot
for either autocorrelation, conditional heteroskedasticity, or distribution,
or simply draws the residual time series.
Usage
diagnostic_plot(
stvar,
type = c("all", "series", "ac", "ch", "dist"),
resid_type = c("standardized", "raw"),
maxlag = 12
)
Arguments
stvar |
object of class |
type |
which type of diagnostic plot should be plotted?
|
resid_type |
should standardized or raw residuals be used? |
maxlag |
the maximum lag considered in types |
Details
Auto- and cross-correlations (types "ac"
and "ch"
) are calculated with the function
acf
from the package stats
and the plot method for class 'acf'
objects is employed.
If cond_dist == "Student"
or "ind_Student"
, the estimates of the degrees of freedom parameters is used in
theoretical densities and quantiles. If cond_dist == "ind_skewed_t"
, the estimates of the degrees of freedom and
skewness parameters are used in theoretical densities and quantiles, and the quantile function is computed numerically.
Value
No return value, called for its side effect of plotting the diagnostic plot.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
Portmanteau_test
, profile_logliks
, fitSTVAR
, STVAR
,
LR_test
, Wald_test
, Rao_test
Examples
## Gaussian STVAR p=1, M=2 model, with weighted relative stationary densities
# of the regimes as the transition weight function:
theta_122relg <- c(0.734054, 0.225598, 0.705744, 0.187897, 0.259626, -0.000863,
-0.3124, 0.505251, 0.298483, 0.030096, -0.176925, 0.838898, 0.310863, 0.007512,
0.018244, 0.949533, -0.016941, 0.121403, 0.573269)
mod122 <- STVAR(data=gdpdef, p=1, M=2, params=theta_122relg)
# Autocorelation function of raw residuals for checking remaining autocorrelation:
diagnostic_plot(mod122, type="ac", resid_type="raw")
# Autocorelation function of squared standardized residuals for checking remaining
# conditional heteroskedasticity:
diagnostic_plot(mod122, type="ch", resid_type="standardized")
# Below, ACF of squared raw residuals, which is not very informative for evaluating
# adequacy to capture conditional heteroskedasticity, since it doesn't take into account
# the time-varying conditional covariance matrix of the model:
diagnostic_plot(mod122, type="ch", resid_type="raw")
# Similarly, below the time series of raw residuals first, and then the
# time series of standardized residuals. The latter is more informative
# for evaluating adequacy:
diagnostic_plot(mod122, type="series", resid_type="raw")
diagnostic_plot(mod122, type="series", resid_type="standardized")
# Also similarly, histogram and Q-Q plots are more informative for standardized
# residuals when evaluating model adequacy:
diagnostic_plot(mod122, type="dist", resid_type="raw") # Bad fit for GDPDEF
diagnostic_plot(mod122, type="dist", resid_type="standardized") # Good fit for GDPDEF
## Linear Gaussian VAR p=1 model:
theta_112 <- c(0.649526, 0.066507, 0.288526, 0.021767, -0.144024, 0.897103,
0.601786, -0.002945, 0.067224)
mod112 <- STVAR(data=gdpdef, p=1, M=1, params=theta_112)
diagnostic_plot(mod112, resid_type="standardized") # All plots for std. resids
diagnostic_plot(mod112, resid_type="raw") # All plots for raw residuals
Internal estimation function for estimating autoregressive and threshold parameters of TVAR models by the method of least squares.
Description
estim_LS
estimates the autoregressive and threshold parameters of TVAR models
by the method of least squares.
Usage
estim_LS(
data,
p,
M,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
penalized = TRUE,
penalty_params = c(0.05, 0.2),
min_obs_coef = 3,
sparse_grid = FALSE,
use_parallel = TRUE,
ncores = 2
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
min_obs_coef |
the smallest accepted number of observations (times variables) from each regime
relative to the number of parameters in the regime. For models with AR constraints, the number of
AR matrix parameters in each regimes is simplisticly assumed to be |
sparse_grid |
should the grid of weight function values in LS/NLS estimation be more sparse (speeding up the estimation)? |
use_parallel |
employ parallel computing? If |
ncores |
the number CPU cores to be used in parallel computing. |
Details
Used internally in the multiple phase estimation procedure proposed by Koivisto, Luoto, and Virolainen (2025). Mean constraints are not supported. Only weight constraints that specify the threshold parameters as fixed values are supported. Only intercept parametrization is supported.
Value
Returns the estimated parameters in a vector of the form
(\phi_{1},...,\phi_{M},\varphi_1,...,\varphi_M,\alpha
, where
\phi_{m} =
the(d \times 1)
intercept vector of them
th regime.\varphi_m = (vec(A_{m,1}),...,vec(A_{m,p}))
(pd^2 \times 1)
.\alpha = (r_1,...,r_{M-1})
the(M-1\times 1)
vector of the threshold parameters.
For models with...
- AR_constraints:
Replace
\varphi_1,...,\varphi_M
with\psi
as described in the argumentAR_constraints
.- weight_constraints:
If linear constraints are imposed, replace
\alpha
with\xi
as described in the argumentweigh_constraints
. If weight functions parameters are imposed to be fixed values, simply drop\alpha
from the parameter vector.
References
Hubrich K., Teräsvirta. T. 2013. Thresholds and Smooth Transitions in Vector Autoregressive Models. CREATES Research Paper 2013-18, Aarhus University.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
Internal estimation function for estimating autoregressive and weight parameters of STVAR models by the method of nonlinear least squares.
Description
estim_NLS
estimates the autoregressive and weight parameters of STVAR models
by the method of least squares (relative_dens
weight function is not supported).
Usage
estim_NLS(
data,
p,
M,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
penalized = TRUE,
penalty_params = c(0.05, 0.2),
min_obs_coef = 3,
sparse_grid = FALSE,
use_parallel = TRUE,
ncores = 2
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
min_obs_coef |
the smallest accepted number of observations (times variables) from each regime
relative to the number of parameters in the regime. For models with AR constraints, the number of
AR matrix parameters in each regimes is simplisticly assumed to be |
sparse_grid |
should the grid of weight function values in LS/NLS estimation be more sparse (speeding up the estimation)? |
use_parallel |
employ parallel computing? If |
ncores |
the number CPU cores to be used in parallel computing. |
Details
Used internally in the multiple phase estimation procedure proposed by Virolainen (2025).
The weight function relative_dens
is not supported. Mean constraints are not supported.
Only weight constraints that specify the weight parameters as fixed values are supported.
Only intercept parametrization is supported.
Value
Returns the estimated parameters in a vector of the form
(\phi_{1},...,\phi_{M},\varphi_1,...,\varphi_M,\alpha
, where
\phi_{m} =
the(d \times 1)
intercept vector of them
th regime.\varphi_m = (vec(A_{m,1}),...,vec(A_{m,p}))
(pd^2 \times 1)
.\alpha
is the vector of the weight parameters:weight_function="relative_dens"
:\alpha = (\alpha_1,...,\alpha_{M-1})
(M - 1 \times 1)
, where\alpha_m
(1\times 1), m=1,...,M-1
are the transition weight parameters.weight_function="logistic"
:\alpha = (c,\gamma)
(2 \times 1)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.weight_function="mlogit"
:\alpha = (\gamma_1,...,\gamma_M)
((M-1)k\times 1)
, where\gamma_m
(k\times 1)
,m=1,...,M-1
contains the multinomial logit-regression coefficients of them
th regime. Specifically, for switching variables with indices inI\subset\lbrace 1,...,d\rbrace
, and with\tilde{p}\in\lbrace 1,...,p\rbrace
lags included,\gamma_m
contains the coefficients for the vectorz_{t-1} = (1,\tilde{z}_{\min\lbrace I\rbrace},...,\tilde{z}_{\max\lbrace I\rbrace})
, where\tilde{z}_{i} =(y_{it-1},...,y_{it-\tilde{p}})
,i\in I
. Sok=1+|I|\tilde{p}
where|I|
denotes the number of elements inI
.weight_function="exponential"
:\alpha = (c,\gamma)
(2 \times 1)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.weight_function="threshold"
:\alpha = (r_1,...,r_{M-1})
(M-1 \times 1)
, wherer_1,...,r_{M-1}
are the thresholds.weight_function="exogenous"
:Omit
\alpha
from the parameter vector.
For models with...
- AR_constraints:
Replace
\varphi_1,...,\varphi_M
with\psi
as described in the argumentAR_constraints
.- weight_constraints:
If linear constraints are imposed, replace
\alpha
with\xi
as described in the argumentweigh_constraints
. If weight functions parameters are imposed to be fixed values, simply drop\alpha
from the parameter vector.
References
Hubrich K., Teräsvirta. T. 2013. Thresholds and Smooth Transitions in Vector Autoregressive Models. CREATES Research Paper 2013-18, Aarhus University.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
Filter inappropriate the estimates produced by fitSTVAR
Description
filter_estimates
filters out inappropriate estimates produced by fitSTVAR
:
can be used to obtain the (possibly) appropriate estimate with the largest found log-likelihood
(among possibly appropriate estimates) as well as (possibly) appropriate estimates based on smaller
log-likelihoods.
Usage
filter_estimates(
stvar,
which_largest = 1,
filter_stab = TRUE,
calc_std_errors = FALSE
)
Arguments
stvar |
a class 'stvar' object defining a structural STVAR model that is identified by heteroskedasticity
or non-Gaussianity, typically created with |
which_largest |
an integer at least one specifying the (possibly) appropriate estimate corresponding
to which largest log-likelihood should be returned. E.g., if |
filter_stab |
Should estimates close to breaking the usual stability condition be filtered out? |
calc_std_errors |
should approximate standard errors be calculated? |
Details
The function goes through the estimates produced by fitSTVAR
and checks which estimates are
deemed inappropriate. That is, estimates that are not likely solutions of interest. Specifically, solutions
that incorporate a near-singular error term covariance matrix (any eigenvalue less than 0.002
),
any modulus of the eigenvalues of the companion form AR matrices larger than $0.9985$ (indicating the
necessary condition for stationarity is close to break), or transition weights such that they are close to zero
for almost all t
for at least one regime. Then, among the solutions are not deemed inappropriate, it
returns a STVAR models based on the estimate that has the which_largest
largest log-likelihood.
The function filter_estimates
is kind of a version of alt_stvar
that only considers estimates
that are not deemed inappropriate
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
See Also
Examples
# Fit a two-regime STVAR model with logistic transition weights and Student's t errors,
# and use two-phase estimation method:
fit12 <- fitSTVAR(gdpdef, p=1, M=2, weight_function="logistic", weightfun_pars=c(2, 1),
cond_dist="Student", nrounds=2, ncores=2, seeds=1:2, estim_method="two-phase")
fit12
# Filter through inappropriate estimates and obtain the second best appropriate solution:
fit12_2 <- filter_estimates(fit12, which_largest=2)
fit12_2 # The same model since the two estimation rounds yielded the same estimate
Maximum likelihood estimation of a structural STVAR model based on preliminary estimates from a reduced form model.
Description
fitSSTVAR
uses a robust method and a variable metric algorithm to estimate
a structural STVAR model based on preliminary estimates from a reduced form model.
Usage
fitSSTVAR(
stvar,
identification = c("recursive", "heteroskedasticity", "non-Gaussianity"),
B_constraints = NULL,
B_pm_reg = NULL,
B_perm = NULL,
B_signs = NULL,
maxit = 1000,
maxit_robust = 1000,
h = 0.001,
robust_method = c("Nelder-Mead", "SANN", "none"),
print_res = TRUE,
calc_std_errors = TRUE
)
Arguments
stvar |
a an object of class |
identification |
Which identification should the structural model use? (see the vignette or the references for details)
|
B_constraints |
Employ further constraints on the impact matrix?
A |
B_pm_reg |
an integer between |
B_perm |
a numeric vector of length |
B_signs |
a numeric vector specifying the columns of the impact matrix of a single regime specified in the argument
|
maxit |
the maximum number of iterations in the variable metric algorithm. |
maxit_robust |
the maximum number of iterations on the first phase robust estimation, if employed. |
h |
the strictly positive difference used in the finite difference approximation of the gradient used in numerical optimization. |
robust_method |
Should some robust estimation method be used in the estimation before switching to the gradient based variable metric algorithm? See details. |
print_res |
should summaries of estimation results be printed? |
calc_std_errors |
Calculate approximate standard errors (based on standard asymptotics)? |
Details
When the structural model does not impose overidentifying constraints, it is directly obtained from the reduced form model, and estimation is not required. When overidentifying constraints are imposed, the model is estimated subject to the constraints.
Using the robust estimation method before switching to the variable metric can be useful if the initial estimates are not very close to the ML estimate of the structural model, as the variable metric algorithm (usually) converges to a nearby local maximum or saddle point. However, if the initial estimates are far from the ML estimate, the resulting solution is likely local only due to the complexity of the model. Note that Nelder-Mead algorithm is much faster than SANN but can get stuck at a local solution. This is particularly the case when the imposed overidentifying restrictions are such that the unrestricted estimate is not close to satisfying them. Nevertheless, in most practical cases, the model is just identified and estimation is not required, and often reasonable overidentifying constraints are close to the unrestricted estimate.
Employs the estimation function optim
from the package stats
that implements the optimization
algorithms. See ?optim
for the documentation on the optimization methods.
The arguments B_pm_reg
, B_perm
, and B_signs
can be used to explore estimates based various orderings
and sign changes of the columns of the impact matrices B_m
of specific regimes. This can be useful in the presence
of weak identification with respect to the ordering or signs of the columns B_2,...,B_M
(see Virolainen 2025).
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
References
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Lütkepohl H., Netšunajev A. 2017. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
Examples
## These are long running examples that take approximately 1 minute to run.
## Estimate first a reduced form Gaussian STVAR p=3, M=2 model with the weighted relative
# stationary densities of the regimes as the transition weight function, and the means and
# AR matrices constrained to be identical across the regimes:
fit32cm <- fitSTVAR(gdpdef, p=3, M=2, AR_constraints=rbind(diag(3*2^2), diag(3*2^2)),
weight_function="relative_dens", mean_constraints=list(1:2), parametrization="mean",
nrounds=1, seeds=1, ncores=1)
# Then, we estimate/create various structural models based on the reduced form model.
# Create a structural model with the shocks identified recursively:
fit32cms_rec <- fitSSTVAR(fit32cm, identification="recursive")
# Create a structural model with the shocks identified by conditional heteroskedasticity:
fit32cms_hetsked <- fitSSTVAR(fit32cm, identification="heteroskedasticity")
fit32cms_hetsked # Print the estimates
# Estimate a structural model with the shocks identified by conditional heteroskedasticity
# and overidentifying constraints imposed on the impact matrix: positive diagonal element
# and zero upper right element:
fit32cms_hs2 <- fitSSTVAR(fit32cm, identification="heteroskedasticity",
B_constraints=matrix(c(1, NA, 0, 1), nrow=2))
# Estimate a structural model with the shocks identified by conditional heteroskedasticity
# and overidentifying constraints imposed on the impact matrix: positive diagonal element
# and zero off-diagonal elements:
fit32cms_hs3 <- fitSSTVAR(fit32cms_hs2, identification="heteroskedasticity",
B_constraints=matrix(c(1, 0, 0, 1), nrow=2))
# Estimate first a reduced form two-regime Threshold VAR p=1 model with
# with independent skewed t shocks, and the first lag of the second variable
# as the switching variable, and AR matrices constrained to be identical
# across the regimes:
fit12c <- fitSTVAR(gdpdef, p=1, M=2, cond_dist="ind_skewed_t",
AR_constraints=rbind(diag(1*2^2), diag(1*2^2)), weight_function="threshold",
weightfun_pars=c(2, 1), nrounds=1, seeds=1, ncores=1)
# Due to the independent non-Gaussian shocks, the structural shocks are readily
# identified. The following returns the same model but marked as structural
# with the shocks identified by non-Gaussianity:
fit12c <- fitSSTVAR(fit12c)
# Estimate a model based on a reversed ordering of the columns of the impact matrix B_2:
fit12c2 <- fitSSTVAR(fit12c, B_pm_reg=2, B_perm=c(2, 1))
# Estimate a model based on reversed signs of the second column of B_2 and reversed
# ordering of the columns of B_2:
fit12c3 <- fitSSTVAR(fit12c, B_pm_reg=2, B_perm=c(2, 1), B_signs=2)
Two-phase or three-phase (penalized) maximum likelihood estimation of a reduced form smooth transition VAR model
Description
fitSTVAR
estimates a reduced form smooth transition VAR model in two phases
or three phases. In additional ML estimation, also penalized ML estimation is available.
Usage
fitSTVAR(
data,
p,
M,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
estim_method,
penalized,
penalty_params = c(0.05, 0.2),
allow_unstab,
min_obs_coef = 3,
sparse_grid = FALSE,
h = 0.001,
nrounds,
ncores = 2,
maxit = 2000,
seeds = NULL,
print_res = TRUE,
use_parallel = TRUE,
calc_std_errors = TRUE,
...
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
estim_method |
either |
penalized |
should penalized log-likelihood function be used that penalizes the log-likelihood function when
the parameter values are close the boundary of the stability region or outside it? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
min_obs_coef |
In the LS/NLS step of the three phase estimation, the smallest accepted number of observations
(times variables) from each regime relative to the number of parameters in the regime. For models with AR constraints,
the number of AR matrix parameters in each regimes is simply assumed to be |
sparse_grid |
should the grid of weight function values in LS/NLS estimation be more sparse (speeding up the estimation)? |
h |
the strictly positive difference used in the finite difference approximation of the gradient used in numerical optimization. |
nrounds |
the number of estimation rounds that should be performed. The default is |
ncores |
the number CPU cores to be used in parallel computing. |
maxit |
the maximum number of iterations in the variable metric algorithm. |
seeds |
a length |
print_res |
should summaries of estimation results be printed? |
use_parallel |
employ parallel computing? If |
calc_std_errors |
Calculate approximate standard errors (based on standard asymptotics)? |
... |
additional settings passed to the function |
Details
If you wish to estimate a structural model, estimate first the reduced form model and then use the
use the function fitSSTVAR
to create (and estimate if necessary) the structural model
based on the estimated reduced form model.
three-phase estimation. With estim_method="three-phase"
(not available for models with relative_dens
weight function), an extra phase is added to the beginning of the two-phase estimation procedure:
the autoregressive and weight function parameters are first estimated by the method of (penalized) least squares. Then,
the rest of the parameters are estimated by (penalized) ML with the genetic algorithm conditionally on the LS estimates.
Finally, all the parameters are estimated by (penalized) ML by initializing a gradient based variable metric algorithm
from initial estimates obtained from the first two phases. This allows to use substantially decrease the required
number of estimation rounds, and thereby typically speeds up the estimation substantially. On the other hand, the three-phase
procedure tends to produce estimates close to the initial (penalized) LS estimates, while the two-phase procedure explores
the parameter space more thoroughly (when a large enough number of estimation rounds is ran).
Penalized estimation. The penalized estimation (penalized=TRUE
) maximizes the penalized log-likelihood function
in which a penalty term is added. The penalty term becomes nonzero when the parameter values are close to the boundary of the
stability region or outside it, it increases in the modulus of the eigenvalues of the companion form AR matrices of the regimes.
With allow_unstab=TRUE
, allowing for unstable estimates, it allows the estimation algorithms to explore the parameter space
outside the stability region, but with high enough penalization, the optimization algorithm eventually converges back to the
stability region. By default, penalized estimation (with unstable estimates allow) is used for estim_method="three-phase"
and not used for estim_method="two-phase"
.
The rest concerns both two-phase and three-phase procedures.\
Because of complexity and high multimodality of the log-likelihood function, it is not certain
that the estimation algorithm will end up in the global maximum point. When estim_method="two-phase"
,
it is expected that many of the estimation rounds will end up in some local maximum or a saddle point instead.
Therefore, a (sometimes very large) number of estimation rounds is required for reliable results
(when estim_method="three-phase"
substantially smaller number should be sufficient). Due to
identification problems and high complexity of the surface of the log-likelihood function, the estimation may
fail especially in the cases where the number of regimes is chosen too large.
The estimation process is computationally heavy and it might take considerably long time for large models to
estimate, particularly if estim_method="two-phase"
. Note that reliable estimation of model with
cond_dist == "ind_Student"
or "ind_skewed_t"
is more difficult than with Gaussian or Student's t
models due to the increased complexity.
If the iteration limit maxit
in the variable metric algorithm is reached, one can continue the estimation by
iterating more with the function iterate_more
. Alternatively, one may use the found estimates as starting values
for the genetic algorithm and employ another round of estimation (see ??GAfit
how to set up an initial population
with the dot parameters).
If the estimation algorithm performs poorly, it usually helps to scale the individual series so that they vary roughly in the same scale. This makes it is easier to draw reasonable AR coefficients and (with some weight functions) weight parameter values in the genetic algorithm. Even if the estimation algorithm somewhat works, it should be preferred to scale the data so that most of the AR coefficients will not be very large, as the genetic algorithm works better with relatively small AR coefficients. If needed, another package can be used to fit linear VARs to the series to see which scaling of the series results in relatively small AR coefficients. You should avoid very small (or very high) variance in the data as well, so that the eigenvalues of the covariance matrices are in a reasonable range.
weight_constraints: If you are using weight constraints other than restricting some of the weight parameters to known constants, make sure the constraints are sensible. Otherwise, the estimation may fail due to the estimation algorithm not being able to generate reasonable random guesses for the values of the constrained weight parameters.
Filtering inappropriate estimates: fitSTVAR
automatically filters through estimates
that it deems "inappropriate". That is, estimates that are not likely solutions of interest.
Specifically, solutions that incorporate a near-singular error term covariance matrix (any eigenvalue less than 0.002
),
any modulus of the eigenvalues of the companion form AR matrices larger than $0.9985$ (indicating the necessary condition for
stationarity is close to break), or transition weights such that they are close to zero for almost all t
for at least
one regime. You can also always find the solutions of interest yourself by using the function alt_stvar
as well since
results from all estimation rounds are saved).
Passing arguments to the genetic algorithm: The settings of the genetic algorithm can be adjusted by passing arguments
to it via the dot parameters. See all the available options from the documentation of the function GAfit
with the command
??GAfit
.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
S3 methods
The following S3 methods are supported for class 'stvar'
: logLik
, residuals
, print
, summary
,
predict
, simulate
, and plot
.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hubrich K., Teräsvirta. T. 2013. Thresholds and Smooth Transitions in Vector Autoregressive Models. CREATES Research Paper 2013-18, Aarhus University.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
fitSSTVAR
, STVAR
, GAfit
, iterate_more
, filter_estimates
Examples
## These are long running examples. Running all the below examples will take
## approximately three minutes.
# When estimating the models in empirical applications, typically a large number
# of estimation rounds (set by the argument 'nrounds') should be used. These examples
# use only a small number of rounds to make the running time of the examples reasonable.
# The below examples make use of the two-variate dataset 'gdpdef' containing
# the the quarterly U.S. GDP and GDP deflator from 1947Q1 to 2019Q4.
# Estimate Gaussian STVAR model of autoregressive order p=3 and two regimes (M=2),
# with the weighted relative stationary densities of the regimes as the transition
# weight function. The estimation is performed with 2 rounds and 2 CPU cores, with
# the random number generator seeds set for reproducibility (two-phase estimation):
fit32 <- fitSTVAR(gdpdef, p=3, M=2, weight_function="relative_dens", cond_dist="Gaussian",
nrounds=2, ncores=2, seeds=1:2)
# Examine the results:
fit32 # Printout of the estimates
summary(fit32) # A more detailed summary printout
plot(fit32) # Plot the fitted transition weights
get_foc(fit32) # Gradient of the log-likelihood function about the estimate
get_soc(fit32) # Eigenvalues of the Hessian of the log-lik. fn. about the estimate
profile_logliks(fit32) # Profile log-likelihood functions about the estimate
# Estimate a two-regime Student's t STVAR p=5 model with logistic transition weights
# and the first lag of the second variable as the switching variable, only two
# estimation rounds using two CPU cores (three-phase estimation):
fitlogistict32 <- fitSTVAR(gdpdef, p=3, M=2, weight_function="logistic", weightfun_pars=c(2, 1),
cond_dist="Student", nrounds=2, ncores=2, seeds=1:2)
summary(fitlogistict32) # Summary printout of the estimates
# Estimate a two-regime threshold VAR p=3 model with independent skewed t shocks
# using the three-phase estimation procedure.
# The first lag of the the second variable is specified as the switching variable,
# and the threshold parameter constrained to the fixed value 1 (three-phase estimation):
fitthres32wit <- fitSTVAR(gdpdef, p=3, M=2, weight_function="threshold", weightfun_pars=c(2, 1),
cond_dist="ind_skewed_t", weight_constraints=list(R=0, r=1), nrounds=2, ncores=2, seeds=1:2)
plot(fitthres32wit) # Plot the fitted transition weights
# Estimate a two-regime STVAR p=1 model with exogenous transition weights defined as the indicator
# of NBER based U.S. recessions (source: St. Louis Fed database). Moreover, restrict the AR matrices
# to be identical across the regimes (i.e., allowing for time-variation in the intercepts and the
# covariance matrix only), (three-phase estimation):
# Step 1: Define transition weights of Regime 1 as the indicator of NBER based U.S. recessions
# (the start date of weights is start of data + p, since the first p values are used as the initial
# values):
tw1 <- c(0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
# Step 2: Define the transition weights of Regime 2 as one minus the weights of Regime 1, and
# combine the weights to matrix of transition weights:
twmat <- cbind(tw1, 1 - tw1)
# Step 3: Create the appropriate constraint matrix:
C_122 <- rbind(diag(1*2^2), diag(1*2^2))
# Step 4: Estimate the model by specifying the weights in the argument 'weightfun_pars'
# and the constraint matrix in the argument 'AR_constraints':
fitexo12cit <- fitSTVAR(gdpdef, p=1, M=2, weight_function="exogenous", weightfun_pars=twmat,
cond_dist="ind_Student", AR_constraints=C_122, nrounds=2, ncores=2, seeds=1:2)
plot(fitexo12cit) # Plot the transition weights
summary(fitexo12cit) # Summary printout of the estimates
# Estimate a two-regime Gaussian STVAR p=1 model with the weighted relative stationary densities
# of the regimes as the transition weight function; constrain AR matrices to be identical
# across the regimes and also constrain the off-diagonal elements of the AR matrices to be zero.
# Moreover, constrain the unconditional means of both regimes to be equal (two-phase estimation):
mat0 <- matrix(c(1, rep(0, 10), 1, rep(0, 8), 1, rep(0, 10), 1), nrow=2*2^2, byrow=FALSE)
C_222 <- rbind(mat0, mat0) # The constraint matrix
fit22cm <- fitSTVAR(gdpdef, p=2, M=2, weight_function="relative_dens", cond_dist="Gaussian",
parametrization="mean", AR_constraints=C_222, mean_constraints=list(1:2), nrounds=2, seeds=1:2)
fit22cm # Print the estimates
# Estimate a two-regime Student's t STVAR p=3 model with logistic transition weights and the
# first lag of the second variable as the switching variable. Constraint the location parameter
# to the fixed value 1 and leave the scale parameter unconstrained (three-phase estimation):
fitlogistic32w <- fitSTVAR(gdpdef, p=3, M=2, weight_function="logistic", weightfun_pars=c(2, 1),
cond_dist="Student", weight_constraints=list(R=matrix(c(0, 1), nrow=2), r=c(1, 0)), nrounds=2,
seeds=1:2)
plot(fitlogistic32w) # Plot the fitted transition weights
Internal estimation function for estimating STVAR model when bootstrapping confidence
bounds for IRFs in linear_IRF
Description
fitbsSSTVAR
uses a robust method and a variable metric algorithm to estimate
a structural STVAR model based on preliminary estimates.
Usage
fitbsSSTVAR(
data,
p,
M,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
other_constraints = NULL,
robust_method = c("Nelder-Mead", "SANN", "none"),
penalized = FALSE,
penalty_params = c(0.05, 0.2),
allow_unstab = FALSE,
minval = NULL,
maxit = 1000,
maxit_robust = 1000,
seed = NULL
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
other_constraints |
A list containing internally used additional type of constraints (see the options below).
|
robust_method |
Should some robust estimation method be used in the estimation before switching to the gradient based variable metric algorithm? See details. |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
minval |
the value that will be returned if the parameter vector does not lie in the parameter space (excluding the identification condition). |
maxit |
the maximum number of iterations in the variable metric algorithm. |
maxit_robust |
the maximum number of iterations on the first phase robust estimation, if employed. |
seed |
the seed for the random number generator (relevant when using SANN). |
Details
Used internally in the functions linear_IRF
for estimating the model in each bootstrap replication.
Employs the estimation function optim
from the package stats
that implements the optimization
algorithms.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
warning
No argument checks!
References
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Lütkepohl H., Netšunajev A. 2017. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
Form the (dp\times dp)
"bold A" matrices related to the VAR processes
Description
form_boldA
creates the "bold A" (companien form) coefficient matrices related to
VAR processes.
Usage
form_boldA(p, M, d, all_A)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
all_A |
4D array containing all coefficient matrices |
Details
The "bold A" (companion form) matrix is given, for instance, in Lütkepohl (2005, p. 15).
Value
Returns 3D array containing the (dp \times dp)
"bold A" matrices related to each component VAR-process.
The matrix A_{m}
can be obtained by choosing [, , m]
.
Warning
No argument checks!
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Function factory for value formatting
Description
format_valuef
is a function factory for
formatting values with certain number of digits.
Usage
format_valuef(digits)
Arguments
digits |
the number of decimals to print |
Value
Returns a function that takes an atomic vector as argument
and returns it formatted to character with digits
decimals.
U.S. real GDP percent change and GDP implicit price deflator percent change
Description
A dataset containing a quarterly U.S. time series with two components: the percentage change of real GDP and the percentage change of GDP implicit price deflator, covering the period from 1959Q1 - 2019Q4.
Usage
gdpdef
Format
A numeric matrix of class 'ts'
with 244 rows and 2 columns with one time series in each column:
- First column (GDP):
The quarterly percent change of real U.S. GDP, from 1959Q1 to 2019Q4, https://fred.stlouisfed.org/series/GDPC1.
- Second column (GDPDEF):
The quarterly percent change of U.S. GDP implicit price deflator, from 1959Q1 to 2019Q4, https://fred.stlouisfed.org/series/GDPDEF.
Source
The Federal Reserve Bank of St. Louis database
Generate random samples from the skewed t-distribution
Description
generate_skewed_t
generates n
random observations from the univariate skewed t-distribution
described in Hansen (1994) using the acceptance-rejection sampling method.
Usage
generate_skewed_t(n, nu, lambda, bc_M)
Arguments
n |
An integer specifying the number of random observations to generate. Must be a positive integer. |
nu |
A numeric scalar specifying the degrees of freedom parameter for the skewed t-distribution. Must be greater than 2. |
lambda |
A numeric scalar specifying the skewness parameter for the skewed t-distribution. Must be between |
bc_M |
An optional numeric scalar specifying the bounding constant |
Details
The function implements the acceptance-rejection algorithm to generate random samples from the skewed t-distribution.
The proposal distribution used is a standard t-distribution with degrees of freedom proposal_nu
, which is set to 3
when nu > 3
to ensure heavier tails and accommodate the skewness of the target distribution.
If bounding_const_M
is not provided, it is calculated using the bounding_const_M
function. It is important that
the same proposal distribution is used in both the computation of bounding_const_M
and the acceptance-rejection sampling
algorithm to ensure correctness.
Value
A numeric vector of length n
containing random observations from the skewed t-distribution with
parameters nu
and lambda
.
References
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Compute the impact matrix B_{y,t}
for a single time period
Description
get_B_yt
computes the impact matrix B_{y,t}
. For "ind_Student"
and "ind_skewed_t"
models
B_{y,t}=\sum_{m=1}^M\alpha_{m,t}B_m
. For models identified by heteroskedasticity B_{y,t}=W\sqrt{\sum_{m=1}^M\alpha_{m,t}\Lambda_m}
.
For recursive identification B_{y,t}
is obtained from the Cholesky decomposition of the conditional covariance matrix.
Usage
get_B_yt(
all_Omegas,
alpha_mt,
W,
lambdas,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "non-Gaussianity",
"heteroskedasticity")
)
Arguments
all_Omegas |
a 3D array such that the covariance matrix (or impact matrix |
alpha_mt |
an |
W |
a |
lambdas |
a |
cond_dist |
specifies the conditional distribution of the model as |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
Details
This is used in simulation of the counterfactual scenarios.
Value
Returns the (d \times d)
impact matrix for the time period t
.
Calculate the impact matrix B_t
for all t
for models with a non-Gaussian
conditional distribution with mutually independent shocks.
Description
This internal function takes a cube of matrices (all_Omegas
) and a matrix of weights (alpha_mt
),
and calculates the weighted sums of the matrices in the cube. For each row in alpha_mt
, it computes
a weighted sum of matrices, and returns the (3D array) such that each slice contains the weighted sum of the matrices.
Note that the argument all_Omegas
should contain the impact matrices of the regimes (and not the covariance matrices).
Usage
get_Bt_Cpp(all_Omegas, alpha_mt)
Arguments
all_Omegas |
A cube (3D array) of impact matrices, with each slice being an inveritble square matrix. |
alpha_mt |
A matrix of weights, with as many columns as there are slices in |
Value
An arma::cube value (3D array in R) such that each slice contains the weighted sum of the matrices,
i.e, the impact matrix B_t
for all t
.
Calculate AIC, HQIC, and BIC
Description
get_IC
calculates the information criteria values
AIC, HQIC, and BIC divided by the number of observations.
Usage
get_IC(loglik, npars, T_obs)
Arguments
loglik |
log-likelihood value, preferably non-penalized one. |
npars |
number of (freely estimated) parameters in the model |
T_obs |
numbers of observations with the |
Value
Returns a data frame containing the information criteria values divided by the number of observations.
Calculate the dp-dimensional covariance matrices \Sigma_{m,p}
in the transition weights
with weight_function="relative_dens"
Description
get_Sigmas
calculatesthe dp-dimensional covariance matrices \Sigma_{m,p}
in
the transition weights with weight_function="relative_dens"
so that the algorithm proposed
by McElroy (2017) employed whenever it reduces the computation time.
Usage
get_Sigmas(p, M, d, all_A, all_boldA, all_Omegas)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
all_A |
4D array containing all coefficient matrices |
all_boldA |
3D array containing the |
all_Omegas |
a |
Details
Calculates the dp-dimensional covariance matrix using the formula (2.1.39) in Lütkepohl (2005) when
d*p < 12
and using the algorithm proposed by McElroy (2017) otherwise.
The code in the implementation of the McElroy's (2017) algorithm (in the function VAR_pcovmat
) is
adapted from the one provided in the supplementary material of McElroy (2017). Reproduced under GNU General
Public License, Copyright (2015) Tucker McElroy.
Value
Returns a [dp, dp, M]
array containing the dp-dimensional covariance matrices for each regime.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Compute the autoregression matrices A_{y,t,i}\equiv \sum_{m=1}^M\alpha_{m,t}A_{m,i}
for all lags i=1,...,p
for a single time period
Description
get_allA_yti
computes the autoregression matrices A_{y,t,i}\equiv \sum_{m=1}^M\alpha_{m,t}A_{m,i}
, for all lags i=1,...,p
for a single time period, based on the regime autoregression matrices and transition weights.
Usage
get_allA_yti(all_A, alpha_mt)
Arguments
all_A |
4D array containing the coefficient matrices of all regimes so that coefficient matrix
|
alpha_mt |
an |
Details
This is used in simulation of the counterfactual scenarios.
Value
Returns the 3D array containing the coefficient matrices for the given time period so that the lag i
coefficient matrix A_{y,t,i}
can be obtained by choosing [, , i]
.
Get the transition weights alpha_mt
Description
get_alpha_mt
computes the transition weights.
Usage
get_alpha_mt(
data,
Y2,
p,
M,
d,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
all_A,
all_boldA,
all_Omegas,
weightpars,
all_mu,
epsilon,
log_mvdvalues = NULL
)
Arguments
data |
a matrix or class |
Y2 |
the data arranged as obtained from |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
all_A |
4D array containing all coefficient matrices |
all_boldA |
3D array containing the |
all_Omegas |
A 3D array containing the covariance matrix parameters obtain from
|
weightpars |
numerical vector containing the transition weight parameters, obtained from |
all_mu |
an |
epsilon |
the smallest number such that its exponent is wont classified as numerically zero
(around |
log_mvdvalues |
a |
Details
Note that we index the time series as -p+1,...,0,1,...,T
.
Value
Returns the mixing weights a (T x M)
matrix, so that the t
th row is for the time period t
and m
:th column is for the regime m
.
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Calculate absolute values of the eigenvalues of the "bold A" matrices containing the AR coefficients
Description
get_boldA_eigens
calculates absolute values of the eigenvalues of
the "bold A" matrices containing the AR coefficients for each regime.
Usage
get_boldA_eigens(stvar)
Arguments
stvar |
object of class |
Value
Returns a matrix with d*p
rows and M
columns - one column for each regime.
The m
th column contains the absolute values (or modulus) of the eigenvalues of the "bold A" matrix containing
the AR coefficients correspinding to regime m
.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Calculate absolute values of the eigenvalues of the "bold A" matrices containing the AR coefficients
Description
get_boldA_eigens_par
calculates absolute values of the eigenvalues of
the "bold A" matrices containing the AR coefficients for each regime.
Usage
get_boldA_eigens_par(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
Value
Returns a matrix with d*p
rows and M
columns - one column for each regime.
The m
th column contains the absolute values (or modulus) of the eigenvalues of the "bold A" matrix containing
the AR coefficients corresponding to regime m
.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Switch from two-regime reduced form STVAR model to a structural model identified by heteroskedasticity
Description
get_hetsked_sstvar
constructs structural STVAR model identified by heteroskedasticity
based on a reduced form STVAR model.
Usage
get_hetsked_sstvar(stvar, calc_std_errors = FALSE)
Arguments
stvar |
a an object of class |
calc_std_errors |
Calculate approximate standard errors (based on standard asymptotics)? |
Details
The switch is made by simultaneously diagonalizing the two error term covariance matrices with a well known matrix decomposition (Muirhead, 1982, Theorem A9.9) and then normalizing the diagonal of the matrix W positive (which implies positive diagonal of the impact matrix). Models with more that two regimes are not supported because the matrix decomposition does not generally exists for more than two covariance matrices.
Value
Returns an object of class 'stvar'
defining a structural STVAR model identified by heteroskedasticity,
with the main diagonal of the impact matrix normalized to be positive.
See Also
Muirhead R.J. 1982. Aspects of Multivariate Statistical Theory, Wiley.
Returns the default smallest allowed log-likelihood for given data.
Description
get_minval
returns the default smallest allowed log-likelihood for given data.
Usage
get_minval(data)
Arguments
data |
a matrix or class |
Value
Returns -(10^(ceiling(log10(nrow(data)) + ncol(data))) - 1)
Compute the conditional mean \mu_{y,t}=\phi_{y,t} + \sum_{i=1}^pA_{y,t,i}y_{t-i}
for a single time period
Description
get_mu_yt
computes the conditional mean \mu_{y,t}=\phi_{y,t} + \sum_{i=1}^pA_{y,t,i}y_{t-i}
for a single time period
based on the intercepts, AR matrices, and the vector of lagged observations.
Usage
get_mu_yt(phi_yt, all_A_yti, bold_y_t_minus_1)
Arguments
phi_yt |
a |
all_A_yti |
a 3D array containing the coefficient matrices for the given time period so that the lag |
bold_y_t_minus_1 |
a |
Details
This is used in simulation of the counterfactual scenarios.
Value
Returns the (d \times 1)
vector of the conditional mean for the time period t
.
Calculate the conditional means of the process
Description
Calculates the conditional means \mu_{y,t}
of the process
Usage
get_mu_yt_Cpp(obs, all_phi0, all_A, alpha_mt)
Arguments
obs |
a |
all_phi0 |
a |
all_A |
a |
alpha_mt |
a |
Value
a (T \times d)
matrix such that the i:th row contains the conditional
mean of the process.
Get the new starting time of series that is forwarded some number of steps
Description
get_new_start
calculates the new starting time of series
that is forwarded some number of steps.
Usage
get_new_start(y_start, y_freq, steps_forward)
Arguments
y_start |
original starting time of the series |
y_freq |
frequency of the series |
steps_forward |
how many steps the series should be forwarded? |
Value
Returns a length two numeric vector with the "year" (or "major")
time point in the first element the "quarter/month/week/day" (or "minor")
time in the second element for a series that is forwarded from y_start
steps_forward
steps forward.
Calculate the eigenvalues of the "Omega" error term covariance matrices
Description
get_omega_eigens
calculates the eigenvalues of the "Omega" error
term covariance matrices for each regime
Usage
get_omega_eigens(stvar)
Arguments
stvar |
object of class |
Value
Returns a matrix with d
rows and M
columns - one column for each regime.
The m
th column contains the eigenvalues of the "Omega" error term covariance matrix
of the m
th regime.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Calculate the eigenvalues of the "Omega" error term covariance matrices
Description
get_omega_eigens_par
calculates the eigenvalues of the "Omega" error
term covariance matrices for each regime
Usage
get_omega_eigens_par(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
Value
Returns a matrix with d
rows and M
columns - one column for each regime.
The m
th column contains the eigenvalues of the "Omega" error term covariance matrix
of the m
th regime.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Compute the intercept \phi_{y,t}=\sum_{m=1}^M \alpha_{mt} \phi_{m}
parameter value for a single time period
Description
get_phi_yt
computes the intercept \phi_{y,t}=\sum_{m=1}^M \alpha_{mt} \phi_{m}
parameter
value for a single time period based on the regime intercepts and transition weights.
Usage
get_phi_yt(all_phi0, alpha_mt)
Arguments
all_phi0 |
a |
alpha_mt |
an |
Details
This is used in simulation of the counterfactual scenarios.
Value
Returns the (d \times 1)
vector of the intercept parameter values for the time period t
.
Calculate regimewise autocovariance matrices
Description
get_regime_autocovs
calculates the regimewise autocovariance matrices \Gamma_{m}(j)
j=0,1,...,p
Usage
get_regime_autocovs(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
Value
Returns an (d \times d \times p+1 \times M)
array containing the first p regimewise autocovariance matrices.
The subset [, , j, m]
contains the j-1:th lag autocovariance matrix of the m:th regime.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Calculate regime means \mu_{m}
Description
get_regime_means
calculates regime means \mu_{m} = (I - \sum A)^(-1))
from the given parameter vector.
Usage
get_regime_means(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
Value
Returns a (d\times M)
matrix containing regime mean \mu_{m}
in the m:th column, m=1,..,M
.
Warning
No argument checks!
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Calculate residuals of a smooth transition VAR
Description
get_residuals
calculates residuals of a smooth transition VAR
Usage
get_residuals(
data,
p,
M,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
standardize = TRUE,
structural_shocks = FALSE,
penalized = FALSE,
penalty_params = c(0.05, 0.5),
allow_unstab = FALSE
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
standardize |
standardize the residuals to identity matrix covariance matrix? |
structural_shocks |
If |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
Value
Returns a (T \times d)
matrix containing...
- If
standardize == TRUE
: the standardized Pearson residuals.
- If
standardize == FALSE
: the nonstandardized residuals.
- If
structural_shocks == TRUE
: the structural shocks.
Note that the starting time is p + 1
counted from the beginning of the starting time of the data,
as the first p
observations are used as initial values.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
Calculate symmetric square root matrix of a positive definite covariance matrix
Description
get_symmetric_sqrt
calculates symmetric square root matrix
of a positive definite covariance matrix
Usage
get_symmetric_sqrt(Omega)
Arguments
Omega |
a positive definite covariance matrix |
Value
a vectorized symmetric square root matrix of the matrix Omega
.
Warning
No argument checks!
Compute the observation y_t=\mu_{y,t} + B_{y,t}e_t
for a single time period
Description
get_y_t
computes the observation y_t=\mu_{y,t} + B_{y,t}e_t
for a single time period
based on the conditional mean, impact matrix, and shock vector.
Usage
get_y_t(mu_yt, B_yt, e_t)
Arguments
mu_yt |
a |
B_yt |
a |
e_t |
a |
Details
This is used in simulation of the counterfactual scenarios.
Value
Returns the (d \times 1)
vector of observations for the time period t
.
Compute historical decompositions for structural STVAR models.
Description
hist_decomp
computes historical decompositions for structural STVAR models.
Usage
hist_decomp(stvar)
## S3 method for class 'histdecomp'
plot(x, ..., plot_by_shock = FALSE, which_to_plot)
## S3 method for class 'histdecomp'
print(x, ..., digits = 3, which_vars, which_indices)
Arguments
stvar |
an object of class |
x |
object of class |
... |
currently not in use. |
plot_by_shock |
should the historical decompositions by plotted so that there is one figure for each shock (rather than one figure for each variable)? |
which_to_plot |
a numeric vector with the indices of the variables or shocks
(depending on the argument |
digits |
how many significant digits to print? |
which_vars |
a numeric vector specifying the variables to print. The default is that all the variables are printed. |
which_indices |
a numeric vector specifying the time period indices to print. The default is that all the time periods are printed. |
Details
The historical decomposition quantifies the cumulative effects the shocks to the movements of the variables (see, e.g., Kilian and Lütkepohl, 2017, Section~4.3) The historical decompositions are computed as described in Wong (2018). Note that due to the effect of the "initial conditions" and the "steady state component", which are not attributed to the shocks, the cumulative effects of the shocks do not sum to the observed time series.
Value
Returns a class 'histdecomp'
list with the following elements:
- init_cond_comp
A matrix of size
(T \times d)
containing the contributions of the initial conditions to the movements of the variables at each time point; the elementt, i
giving the contribution at the timet
on the variablei
.- steady_state_comp
A matrix of size
(T \times d)
containing the contributions of the steady state component to the movements of the variables at each time point; the elementt, i
giving the contribution at the timet
on the variablei
.- shock_comp
A matrix of size
(T \times d)
containing the contributions of the shocks to the movements of the variables at each time point; the elementt, i
giving the contribution at the timet
on the variablei
.- contributions_of_shocks
A 3D array of size
(T \times d \times d)
containing the cumulative contributions of the shocks to the movements of the variables at each time point; the elementt, i1, i2
giving the contribution of the shocki1
to the variablei2
at the timet
.- stvar
The original STVAR model object.
Returns the input object x
invisibly.
Functions
-
plot(histdecomp)
: plot method -
print(histdecomp)
: print method
References
Kilian L., Lütkepohl H. 2017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Wong H. 2018. Historical decomposition for nonlinear vector autoregressive models. CAMA Working Paper No. 62/2017, available as SSRN:3057759.
See Also
GIRF
, GFEVD
, linear_IRF
, fitSSTVAR
, cfact_hist
,
cfact_fore
, cfact_girf
Examples
# Recursively identified logistic Student's t STVAR(p=3, M=2) model with the first
# lag of the second variable as the switching variable:
params32logt <- c(0.5959, 0.0447, 2.6279, 0.2897, 0.2837, 0.0504, -0.2188, 0.4008,
0.3128, 0.0271, -0.1194, 0.1559, -0.0972, 0.0082, -0.1118, 0.2391, 0.164, -0.0363,
-1.073, 0.6759, 3e-04, 0.0069, 0.4271, 0.0533, -0.0498, 0.0355, -0.4686, 0.0812,
0.3368, 0.0035, 0.0325, 1.2289, -0.047, 0.1666, 1.2067, 7.2392, 11.6091)
mod32logt <- STVAR(gdpdef, p=3, M=2, params=params32logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="recursive")
# Calculate the historical decomposition:
histdec <- hist_decomp(mod32logt)
# Print historical decomposition for Variable 1 for the first ten time periods:
print(histdec, which_vars=1, which_indices=1:10)
# Plot the historical decomposition for all variables:
plot(histdec)
# Plot the contributions of Shock 1 on the movements of all the variables:
plot(histdec, plot_by_shock=TRUE, which_to_plot=1)
Determine whether the parameter vector is in the parameter space
Description
in_paramspace
checks whether the parameter vector is in the parameter
space.
Usage
in_paramspace(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
B_constraints = NULL,
other_constraints = NULL,
all_boldA,
all_Omegas,
weightpars,
distpars,
transition_weights,
allow_unstab = FALSE,
stab_tol = 0.001,
posdef_tol = 1e-08,
distpar_tol = 1e-08,
weightpar_tol = 1e-08
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
B_constraints |
a |
other_constraints |
A list containing internally used additional type of constraints (see the options below).
|
all_boldA |
3D array containing the |
all_Omegas |
A 3D array containing the covariance matrix parameters obtain from
|
weightpars |
numerical vector containing the transition weight parameters, obtained from |
distpars |
A numeric vector containing the distribution parameters...
|
transition_weights |
(optional; only for models with |
allow_unstab |
If |
stab_tol |
numerical tolerance for stability of condition of the regimes: if the "bold A" matrix of any regime
has eigenvalues larger that |
posdef_tol |
numerical tolerance for positive definiteness of the error term covariance matrices: if the error term covariance matrix of any regime has eigenvalues smaller than this, the parameter is considered to be outside the parameter space. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error. |
distpar_tol |
the parameter vector is considered to be outside the parameter space if the degrees of
freedom parameters is not larger than |
weightpar_tol |
numerical tolerance for weight parameters being in the parameter space. Values closer to to the border of the parameter space than this are considered to be "outside" the parameter space. |
Details
The parameter vector in the argument params
should be unconstrained and reduced form.
Value
Returns TRUE
if the given parameter values are in the parameter space and FALSE
otherwise.
This function does NOT consider identification conditions!
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Calculate log independent multivariate Student's t densities
Description
Calculates logs of independent multivariate Student t densities with varying mean and impact matrix AND EXCLUDING the constant term of the density (the constant is calculated and added in R code). The varying impact matrix is calculated within the function from the impact matrices of the regimes and transition weights.
Usage
ind_Student_densities_Cpp(
obs,
means,
impact_matrices,
alpha_mt,
distpars,
minval,
posdef_tol
)
Arguments
obs |
a |
means |
a |
impact_matrices |
a size |
alpha_mt |
a |
distpars |
a numeric vector of length |
minval |
the value that will be returned if the parameter vector does not lie in the parameter space (excluding the identification condition). |
posdef_tol |
numerical tolerance for positive definiteness of the error term covariance matrices: if the error term covariance matrix of any regime has eigenvalues smaller than this, the parameter is considered to be outside the parameter space. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error. |
Details
Returns minval
if the impact matrix B_t
is not invertible for some t up to the numerical tolerance
posdef_tol
.
Value
A numeric vector of length T
, where each element represents the computed density component for
the corresponding observation.
Calculate log independent multivariate skewed t densities
Description
Calculates logs of independent multivariate skewed t densities with varying mean and impact matrix (including the constant terms of the density). The varying impact matrix is calculated within the function from the impact matrices of the regimes and transition weights.
Usage
ind_skewed_t_densities_Cpp(
obs,
means,
impact_matrices,
alpha_mt,
all_nu,
all_lambda,
minval,
posdef_tol
)
Arguments
obs |
a |
means |
a |
impact_matrices |
a size |
alpha_mt |
a |
all_nu |
a numeric vector of length |
all_lambda |
a numeric vector of length |
minval |
the value that will be returned if the parameter vector does not lie in the parameter space (excluding the identification condition). |
posdef_tol |
numerical tolerance for positive definiteness of the error term covariance matrices: if the error term covariance matrix of any regime has eigenvalues smaller than this, the parameter is considered to be outside the parameter space. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error. |
Details
Returns minval
if the impact matrix B_t
is not invertible for some t up to the numerical tolerance
posdef_tol
.
Value
A numeric vector of length T
, where each element represents the computed density component for
the corresponding observation.
Maximum likelihood estimation of a reduced form or structural STVAR model based on preliminary estimates
Description
iterate_more
uses a variable metric algorithm to estimate a reduced form or structural STVAR model
(object of class 'stvar'
) based on preliminary estimates.
Usage
iterate_more(
stvar,
maxit = 1000,
h = 0.001,
penalized,
penalty_params,
allow_unstab,
calc_std_errors = TRUE,
print_trace = TRUE
)
Arguments
stvar |
an object of class |
maxit |
the maximum number of iterations in the variable metric algorithm. |
h |
the step size used in the central difference approximation of the gradient of the log-likelihood function, so
|
penalized |
should penalized log-likelihood function be used that penalizes the log-likelihood function when
the parameter values are close the boundary of the stability region or outside it? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
calc_std_errors |
Calculate approximate standard errors (based on standard asymptotics)? |
print_trace |
should the trace of the optimization algorithm be printed? |
Details
The purpose of iterate_more
is to provide a simple and convenient tool to finalize
the estimation when the maximum number of iterations is reached when estimating a STVAR model
with the main estimation function fitSTVAR
or fitSSTVAR
.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hubrich K., Teräsvirta. T. 2013. Thresholds and Smooth Transitions in Vector Autoregressive Models. CREATES Research Paper 2013-18, Aarhus University.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
fitSTVAR
, STVAR
, optim
,
swap_B_signs
, reorder_B_columns
Examples
## These are long running examples that take approximately 20 seconds to run.
# Estimate two-regime Gaussian STVAR p=1 model with the weighted relative stationary densities
# of the regimes as the transition weight function, but only 5 iterations of the variable matrix
# algorithm:
fit12 <- fitSTVAR(gdpdef, p=1, M=2, nrounds=1, seeds=1, ncores=1, maxit=5)
# The iteration limit was reached, so the estimate is not local maximum.
# The gradient of the log-likelihood function:
get_foc(fit12) # Not close to zero!
# So, we run more iterations of the variable metric algorithm:
fit12 <- iterate_more(fit12)
# The gradient of the log-likelihood function after iterating more:
get_foc(fit12) # Close (enough) to zero!
Estimate linear impulse response function based on a single regime of a structural STVAR model.
Description
linear_IRF
estimates linear impulse response function based on a single regime
of a structural STVAR model.
Usage
linear_IRF(
stvar,
N = 30,
regime = 1,
which_cumulative = numeric(0),
scale = NULL,
ci = NULL,
bootstrap_reps = 100,
ncores = 2,
robust_method = c("Nelder-Mead", "SANN", "none"),
maxit_robust = 1000,
seed = NULL,
...
)
## S3 method for class 'irf'
plot(x, shocks_to_plot, ...)
## S3 method for class 'irf'
print(x, ..., digits = 2, N_to_print, shocks_to_print)
Arguments
stvar |
an object of class |
N |
a positive integer specifying the horizon how far ahead should the linear impulse responses be calculated. |
regime |
Based on which regime the linear IRF should be calculated?
An integer in |
which_cumulative |
a numeric vector with values in |
scale |
should the linear IRFs to some of the shocks be scaled so that they
correspond to a specific instantaneous response of some specific
variable? Provide a length three vector where the shock of interest
is given in the first element (an integer in |
ci |
a real number in |
bootstrap_reps |
the number of bootstrap repetitions for estimating confidence bounds. |
ncores |
the number of CPU cores to be used in parallel computing when bootstrapping confidence bounds. |
robust_method |
Should some robust estimation method be used in the estimation before switching to the gradient based variable metric algorithm? See details. |
maxit_robust |
the maximum number of iterations on the first phase robust estimation, if employed. |
seed |
a real number initializing the seed for the random generator. |
... |
currently not used. |
x |
object of class |
shocks_to_plot |
IRFs of which shocks should be plotted? A numeric vector
with elements in |
digits |
the number of decimals to print |
N_to_print |
an integer specifying the horizon how far to print the estimates and confidence intervals. The default is that all the values are printed. |
shocks_to_print |
the responses to which should should be printed?
A numeric vector with elements in |
Details
If the autoregressive dynamics of the model are linear (i.e., either M == 1 or mean and AR parameters are constrained identical across the regimes), confidence bounds can be calculated based on a fixed-design wild residual bootstrap method. We employ the method described in Herwartz and Lütkepohl (2014); see also the relevant chapters in Kilian and Lütkepohl (2017).
Employs the estimation function optim
from the package stats
that implements the optimization
algorithms. The robust optimization method Nelder-Mead is much faster than SANN but can get stuck at a local
solution. See ?optim
and the references therein for further details.
For model identified by non-Gaussianity, the signs and ordering of the shocks are normalized by assuming
that the first non-zero element of each column of the impact matrix of Regime 1 is strictly positive and they are
in a decreasing order. Use the argument scale
to obtain IRFs scaled for specific impact responses.
Value
Returns a class 'irf'
list with with the following elements:
$point_est
:a 3D array
[variables, shock, horizon]
containing the point estimates of the IRFs. Note that the first slice is for the impact responses and the slice i+1 for the period i. The response of the variable 'i1' to the shock 'i2' is subsetted as$point_est[i1, i2, ]
.$conf_ints
:bootstrapped confidence intervals for the IRFs in a
[variables, shock, horizon, bound]
4D array. The lower bound is obtained as$conf_ints[, , , 1]
, and similarly the upper bound as$conf_ints[, , , 2]
. The subsetted 3D array is then the bound in a form similar to$point_est
.$all_bootstrap_reps
:IRFs from all of the bootstrap replications in a
[variables, shock, horizon, rep]
. 4D array. The IRF from replication i1 is obtained as$all_bootstrap_reps[, , , i1]
, and the subsetted 3D array is then the in a form similar to$point_est
.- Other elements:
contains some of the arguments the
linear_IRF
was called with.
Functions
-
plot(irf)
: plot method -
print(irf)
: print method
References
Herwartz H. and Lütkepohl H. 2014. Structural vector autoregressions with Markov switching: Combining conventional with statistical identification of shocks. Journal of Econometrics, 183, pp. 104-116.
Kilian L. and Lütkepohl H. 2017. Structural Vectors Autoregressive Analysis. Cambridge University Press, Cambridge.
See Also
GIRF
, GFEVD
, hist_decomp
, cfact_hist
, cfact_fore
,
cfact_girf
, fitSTVAR
, STVAR
, reorder_B_columns
, swap_B_signs
Examples
## These are long running examples that take approximately 10 seconds to run.
## A small number of bootstrap replications is used below to shorten the
## running time (in practice, a larger number of replications should be used).
# p=1, M=1, d=2, linear VAR model with independent Student's t shocks identified
# by non-Gaussianity (arbitrary weight function applied here):
theta_112it <- c(0.644, 0.065, 0.291, 0.021, -0.124, 0.884, 0.717, 0.105, 0.322,
-0.25, 4.413, 3.912)
mod112 <- STVAR(data=gdpdef, p=1, M=1, params=theta_112it, cond_dist="ind_Student",
identification="non-Gaussianity", weight_function="threshold", weightfun_pars=c(1, 1))
mod112 <- swap_B_signs(mod112, which_to_swap=1:2)
# Estimate IRFs 20 periods ahead, bootstrapped 90% confidence bounds based on
# 10 bootstrap replications. Linear model so robust estimation methods are
# not required.
irf1 <- linear_IRF(stvar=mod112, N=20, regime=1, ci=0.90, bootstrap_reps=1,
robust_method="none", seed=1, ncores=1)
plot(irf1)
print(irf1, digits=3)
# p=1, M=2, d=2, Gaussian STVAR with relative dens weight function,
# shocks identified recursively.
theta_122relg <- c(0.734054, 0.225598, 0.705744, 0.187897, 0.259626, -0.000863,
-0.3124, 0.505251, 0.298483, 0.030096, -0.176925, 0.838898, 0.310863, 0.007512,
0.018244, 0.949533, -0.016941, 0.121403, 0.573269)
mod122 <- STVAR(data=gdpdef, p=1, M=2, params=theta_122relg, identification="recursive")
# Estimate IRF based on the first regime 30 period ahead. Scale IRFs so that
# the instantaneous response of the first variable to the first shock is 0.3,
# and the response of the second variable to the second shock is 0.5.
# response of the Confidence bounds
# are not available since the autoregressive dynamics are nonlinear.
irf2 <- linear_IRF(stvar=mod122, N=30, regime=1, scale=cbind(c(1, 1, 0.3), c(2, 2, 0.5)))
plot(irf2)
# Estimate IRF based on the second regime without scaling the IRFs:
irf3 <- linear_IRF(stvar=mod122, N=30, regime=2)
plot(irf3)
# p=3, M=2, d=3, Students't logistic STVAR model with the first lag of the second
# variable as the switching variable. Autoregressive dynamics restricted linear,
# but the volatility regime varies in time, allowing the shocks to be identified
# by conditional heteroskedasticity.
theta_322 <- c(0.7575, 0.6675, 0.2634, 0.031, -0.007, 0.5468, 0.2508, 0.0217, -0.0356,
0.171, -0.083, 0.0111, -0.1089, 0.1987, 0.2181, -0.1685, 0.5486, 0.0774, 5.9398, 3.6945,
1.2216, 8.0716, 8.9718)
mod322 <- STVAR(data=gdpdef, p=3, M=2, params=theta_322, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", mean_constraints=list(1:2),
AR_constraints=rbind(diag(3*2^2), diag(3*2^2)), identification="heteroskedasticity",
parametrization="mean")
## Estimate IRFs 30 periods ahead, bootstrapped 90% confidence bounds based on
# 10 bootstrap replications. Responses of the second variable are accumulated.
irf4 <- linear_IRF(stvar=mod322, N=30, regime=1, ci=0.90, bootstrap_reps=10,
which_cumulative=2, seed=1)
plot(irf4)
Log-likelihood function
Description
loglikelihood
log-likelihood function of a smooth transition VAR model
Usage
loglikelihood(
data,
p,
M,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
other_constraints = NULL,
to_return = c("loglik", "tw", "loglik_and_tw", "terms", "regime_cmeans",
"total_cmeans", "total_ccovs", "B_t"),
check_params = TRUE,
penalized = FALSE,
penalty_params = c(0.05, 0.2),
allow_unstab = FALSE,
bound_by_weights = FALSE,
min_obs_coef = 2.5,
indt_R = FALSE,
alt_par = FALSE,
minval = NULL,
stab_tol = 0.001,
posdef_tol = 1e-08,
distpar_tol = 1e-08,
weightpar_tol = 1e-08
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
other_constraints |
A list containing internally used additional type of constraints (see the options below).
|
to_return |
should the returned object be the log-likelihood, which is the default, or something else? See the section "Value" for all the options. |
check_params |
should it be checked that the parameter vector satisfies the model assumptions? Can be skipped to save computation time if it does for sure. |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
bound_by_weights |
should |
min_obs_coef |
if |
indt_R |
If |
alt_par |
If |
minval |
the value that will be returned if the parameter vector does not lie in the parameter space (excluding the identification condition). |
stab_tol |
numerical tolerance for stability of condition of the regimes: if the "bold A" matrix of any regime
has eigenvalues larger that |
posdef_tol |
numerical tolerance for positive definiteness of the error term covariance matrices: if the error term covariance matrix of any regime has eigenvalues smaller than this, the parameter is considered to be outside the parameter space. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error. |
distpar_tol |
the parameter vector is considered to be outside the parameter space if the degrees of
freedom parameters is not larger than |
weightpar_tol |
numerical tolerance for weight parameters being in the parameter space. Values closer to to the border of the parameter space than this are considered to be "outside" the parameter space. |
Details
Calculates the log-likelihood of the specified model.
Value
- If
to_return="loglik"
: the log-likelihood of the specified model.
- If
to_return=="tw"
: a size
[n_obs-p, M]
matrix containing the transition weights: for m:th component in m:th column.- If
to_return=="loglik_and_tw"
: a list of two elements. The first element (
$loglik
) contains the log-likelihood and the second element ($tw
) contains the transition weights.- If
to_return=="terms"
: a length
n_obs-p
numeric vector containing the termsl_{t}
.- If
to_return=="regime_cmeans"
: an
[n_obs-p, d, M]
array containing the regimewise conditional means.- If
to_return=="total_cmeans"
: a
[n_obs-p, d]
matrix containing the conditional means of the process.- If
to_return=="total_ccovs"
: an
[d, d, n_obs-p]
array containing the conditional covariance matrices of the process.- If
to_return=="B_t"
: an
[d, d, n_obs-p]
array containing the impact matricesB_t
of the process. Available only for models withcond_dist="ind_Student" or "ind_skewed_t"
.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
Compute the j:th power of a square matrix A
Description
mat_power
computes the j:th power of a square matrix A using
exponentiation by squaring.
Usage
mat_power(A, j)
Arguments
A |
A square numeric matrix. |
j |
A natural number representing the power to which the matrix will be raised. |
Value
A matrix which is A raised to the power j.
Calculate the number of (freely estimaed) parameters in the model
Description
n_params
calculates the number of (freely estimaed) parameters in the model.
Usage
n_params(
p,
M,
d,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
Value
Returns the number of parameters in the parameter vector of the specified model.
Warning
No argument checks!
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Reorder columns of a square matrix so that the first nonzero elements are in decreasing order
Description
order_B
takes a square matrix B
as input and reorders its columns
so that the diagonal entries of B
are in decreasing order. The function
is designed to be computationally efficient and ensures that the input is a square matrix.
Usage
order_B(B)
Arguments
B |
A square numeric matrix. |
Value
A square matrix B
with columns reordered so that its
diagonal entries are in a decreasing order.
Pick coefficient matrices
Description
pick_Am
picks the coefficient matrices A_{m,i} (i=1,..,p)
from the given parameter vector for a given regime, so that they are arranged in
a 3D array with the third dimension indicating each lag.
Usage
pick_Am(p, M, d, params, m, structural_pars = NULL)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
m |
which regime? |
Details
Does not support constrained parameter vectors.
Value
Returns a 3D array containing the coefficient matrices of the given regime.
The coefficient matrix A_{m,i}
can be obtained by choosing [, , i]
.
Warning
No argument checks!
Pick coefficient matrix
Description
pick_Ami
picks the coefficient matrix A_{m,i}
from the given parameter vector.
Usage
pick_Ami(p, M, d, params, m, i, unvec = TRUE)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
m |
which regime? |
i |
which lag in |
unvec |
if |
Details
Does not support constrained parameter vectors.
Value
Returns the i:th lag coefficient matrix of m:th regime, A_{m,i}
.
Warning
No argument checks!
Pick covariance matrices
Description
pick_Omegas
picks the covariance matrices \Omega_{m}
or impact matrices B_m
from the given parameter vector so that they are arranged in a 3D array with the third dimension indicating
each regime.
Usage
pick_Omegas(
p,
M,
d,
params,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity")
)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
Details
Constrained parameter vectors are not supported.
Value
Returns a 3D array containing...
- If
identification == "non-Gaussianity"
orcond_dist %in% c("ind_Student", "ind_skewed_t")
: the impact matrices of the regimes,
B_m
in[, , m]
.- If otherwise:
the covariance matrices of the given model,
\Omega_m
in[, , m]
.
Warning
No argument checks!
Pick the structural parameter matrix W
Description
pick_W
picks the structural parameter matrix W from the parameter vector
of a structural model identified by heteroskedasticity.
Usage
pick_W(
p,
M,
d,
params,
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity")
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
Details
Constrained parameter vectors are not supported. Not even constraints in W
!
Value
Returns a (d \times d)
matrix W
for structural models identified by heteroskedasticity
and NULL
for other models.
References
Lütkepohl H., Netšunajev A. 2017. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
Pick all coefficient matrices
Description
pick_allA
picks all coefficient matrices A_{m,i} (i=1,..,p, m=1,..,M)
from the given parameter vector so that they are arranged in a 4D array with the fourth dimension
indicating each regime and third dimension indicating each lag.
Usage
pick_allA(p, M, d, params)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
Details
Does not support constrained parameter vectors.
Value
Returns a 4D array containing the coefficient matrices of all regimes. Coefficient matrix
A_{m,i}
can be obtained by choosing [, , i, m]
.
Warning
No argument checks!
Pick distribution parameters
Description
pick_distpars
picks all the distribution parameters from
the parameter vector
Usage
pick_distpars(
d,
params,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t")
)
Arguments
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
cond_dist |
specifies the conditional distribution of the model as |
Value
Returns...
- If
cond_dist == "Gaussian"
: a numeric vector of length zero.
- If
cond_dist == "Student"
: the degrees of freedom parameter.
- If
cond_dist == "ind_Student"
: a numeric vector of length
d
containing the degrees of freedom parameters.- If
cond_dist == "ind_skewed_t"
: a numeric vector
(\nu_1,...,\nu_d,\lambda_1,...,\lambda_d)
of length2d
containing the degrees of freedom and skewness parameters.
Pick the structural parameter eigenvalues 'lambdas'
Description
pick_lambdas
picks the structural parameters eigenvalue 'lambdas' from the parameter vector
of a structural model identified by heteroskedasticity.
Usage
pick_lambdas(
p,
M,
d,
params,
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity")
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
Details
Constrained parameter vectors are not supported. Not even constraints in W
!
Value
Returns the length (d*(M - 1))
vector (\lambda_{2},...,\lambda_{M})
(see the argument params
) for structural models identified by heteroskedasticity,
numeric(0)
if M=1
, and NULL
for other models.
References
Lütkepohl H., Netšunajev A. 2017. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
Pick \phi_{m}
or \mu_{m}
, m=1,..,M vectors
Description
pick_phi0
picks the intercept or mean parameters from the given parameter vector.
Usage
pick_phi0(M, d, params)
Arguments
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
Details
Does not support constrained parameter vectors.
Value
Returns a (d\times M)
matrix containing \phi_{m}
in the m:th column or
\mu_{m}
if the parameter vector is mean-parametrized, , m=1,..,M
.
Warning
No argument checks!
Pick regime parameters
Description
pick_regime
picks the regime parameters
(\phi_{m},vec(A_{m,1}),...,vec(A_{m,p}),vech(\Omega_m))
Usage
pick_regime(
p,
M,
d,
params,
m,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity")
)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
m |
which regime? |
Details
Constrained models nor structural models are supported.
Value
Returns the vector...
- If
identification == "non-Gaussianity"
orcond_dist %in% c("ind_Student", "ind_skewed_t")
: -
(\phi_{m},vec(A_{m,1}),...,vec(A_{m,p}),vec(B_m))
. - If otherwise:
(\phi_{m},vec(A_{m,1}),...,vec(A_{m,p}),vech(\Omega_m))
.
Note that neither weight parameters or distribution parameters are picked.
Pick transition weight parameters
Description
pick_weightpars
picks the transition weight parameters from the given parameter vector.
Usage
pick_weightpars(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t")
)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
Value
- If
weight_function = "relative_dens"
: Returns a length
M
vector containing the transition weight parameters\alpha_{m}, m=1,...,M
, including the non-parametrized\alpha_{M}
.weight_function="logistic"
:Returns a length two vector
(c,\gamma)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.- If
weight_function = "mlogit"
: Returns a length
(M-1)k
vector(\gamma_1,...,\gamma_M)
, where\gamma_m
(k\times 1)
,m=1,...,M-1
(\gamma_M=0
) contains the mlogit-regression coefficients of them
th regime. Specifically, for switching variables with indices inJ\subset\lbrace 1,...,d\rbrace
, and with\tilde{p}\in\lbrace 1,...,p\rbrace
lags included,\gamma_m
contains the coefficients for the vectorz_{t-1} = (1,\tilde{z}_{\min\lbrace I\rbrace},...,\tilde{z}_{\max\lbrace I\rbrace})
, where\tilde{z}_{i} =(y_{j,t-1},...,y_{j,t-\tilde{p}})
,i\in I
. Sok=1+|I|\tilde{p}
where|I|
denotes the number of elements inI
.weight_function="exponential"
:Returns a length two vector
(c,\gamma)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.weight_function="threshold"
:Returns a length
M-1
vector(r_1,...,r_{M-1})
, wherer_1,...,r_{M-1}
are the threshold values.weight_function="exogenous"
:Returns
numeric(0)
.
Warning
No argument checks!
Predict method for class 'stvar' objects
Description
predict.stvar
is a predict method for class 'stvar'
objects.
Usage
## S3 method for class 'stvarpred'
plot(x, ..., nt, trans_weights = TRUE)
## S3 method for class 'stvar'
predict(
object,
...,
nsteps,
nsim = 1000,
pi = c(0.95, 0.8),
pred_type = c("mean", "median"),
exo_weights = NULL
)
## S3 method for class 'stvarpred'
print(x, ..., digits = 2)
Arguments
x |
object of class |
... |
currently not used. |
nt |
a positive integer specifying the number of observations to be plotted along with the forecast. |
trans_weights |
should forecasts for transition weights be plotted? |
object |
an object of class |
nsteps |
how many steps ahead should be predicted? |
nsim |
to how many independent simulations should the forecast be based on? |
pi |
a numeric vector specifying the confidence levels of the prediction intervals. |
pred_type |
should the pointforecast be based on sample "median" or "mean"? |
exo_weights |
if |
digits |
the number of decimals to print |
Details
The forecasts are computed by simulating multiple sample paths of the future observations and using the sample medians or means as point forecasts and empirical quantiles as prediction intervals.
Value
Returns a class 'stvarpred
' object containing, among the specifications,...
- $pred
Point forecasts
- $pred_ints
Prediction intervals, as
[, , d]
.- $trans_pred
Point forecasts for the transition weights
- $trans_pred_ints
Individual prediction intervals for transition weights, as
[, , m]
, m=1,..,M.
Functions
-
plot(stvarpred)
: predict method -
print(stvarpred)
: print method
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
Examples
# p=2, M=2, d=2, Gaussian relative dens weights
theta_222relg <- c(0.356914, 0.107436, 0.356386, 0.08633, 0.13996, 0.035172,
-0.164575, 0.386816, 0.451675, 0.013086, 0.227882, 0.336084, 0.239257, 0.024173,
-0.021209, 0.707502, 0.063322, 0.027287, 0.009182, 0.197066, 0.205831, 0.005157,
0.025877, 1.092094, -0.009327, 0.116449, 0.592446)
mod222relg <- STVAR(data=gdpdef, p=2, M=2, d=2, params=theta_222relg,
weight_function="relative_dens")
# Predict 10 steps ahead, point forecast based on the conditional
# mean and 90% prediction intervals; prediction based on 100 sample paths:
pred1 <- predict(mod222relg, nsteps=10, nsim=100, pi=0.9, pred_type="mean")
pred1
plot(pred1)
# Predict 7 steps ahead, point forecast based on median and 90%, 80%,
# and 70% prediction intervals; prediction based on 80 sample paths:
pred2 <- predict(mod222relg, nsteps=7, nsim=80, pi=c(0.9, 0.8, 0.7),
pred_type="median")
pred2
plot(pred2)
Plot structural shock time series of a STVAR model
Description
plot_struct_shocks
plots structural shock time series of a structural STVAR model.
For reduced form models (not identified by non-Gaussianity), recursive identification is assumed.
Usage
plot_struct_shocks(stvar)
Arguments
stvar |
object of class |
Details
Plot the time series of the structural shocks of a structural STVAR model.
Value
No return value, called for its side effect of plotting the structural shock time series.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
diagnostic_plot
, fitSTVAR
, fitSSTVAR
, STVAR
,
Examples
## Gaussian STVAR p=1, M=2 model, with weighted relative stationary densities
# of the regimes as the transition weight function:
theta_122relg <- c(0.734054, 0.225598, 0.705744, 0.187897, 0.259626, -0.000863,
-0.3124, 0.505251, 0.298483, 0.030096, -0.176925, 0.838898, 0.310863, 0.007512,
0.018244, 0.949533, -0.016941, 0.121403, 0.573269)
mod122 <- STVAR(data=gdpdef, p=1, M=2, params=theta_122relg)
# Plot the times series structural shocks assuming recursive identification:
plot_struct_shocks(mod122)
Print method for the class hypotest
Description
print.hypotest
is the print method for the class hypotest
objects.
Usage
## S3 method for class 'hypotest'
print(x, ..., digits = 4)
Arguments
x |
object of class |
... |
currently not in use. |
digits |
how many significant digits to print? |
Value
Returns the input object x
invisibly.
Summary print method from objects of class 'stvarsum'
Description
print.stvarsum
is a print method for object 'stvarsum'
generated
by summary.stvar
.
Usage
## S3 method for class 'stvarsum'
print(x, ..., digits, standard_error_print = FALSE)
Arguments
x |
object of class 'stvarsum' generated by |
... |
currently not used. |
digits |
the number of digits to be printed. |
standard_error_print |
if set to |
Value
Returns the input object x
invisibly.
Plot profile log-likelihood functions about the estimates
Description
profile_logliks
plots profile log-likelihood functions about the estimates.
Usage
profile_logliks(
stvar,
which_pars,
scale = 0.1,
nrows,
ncols,
precision = 50,
stab_tol = 0.001,
posdef_tol = 1e-08,
distpar_tol = 1e-08,
weightpar_tol = 1e-08
)
Arguments
stvar |
an object of class |
which_pars |
the profile log-likelihood function of which parameters should be plotted? An integer vector specifying the positions of the parameters in the parameter vector. The parameter vector has the form... |
scale |
a numeric scalar specifying the interval plotted for each estimate:
the estimate plus-minus |
nrows |
how many rows should be in the plot-matrix? The default is |
ncols |
how many columns should be in the plot-matrix? The default is |
precision |
at how many points should each profile log-likelihood function be evaluated at? |
stab_tol |
numerical tolerance for stability of condition of the regimes: if the "bold A" matrix of any regime
has eigenvalues larger that |
posdef_tol |
numerical tolerance for positive definiteness of the error term covariance matrices: if the error term covariance matrix of any regime has eigenvalues smaller than this, the parameter is considered to be outside the parameter space. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error. |
distpar_tol |
the parameter vector is considered to be outside the parameter space if the degrees of
freedom parameters is not larger than |
weightpar_tol |
numerical tolerance for weight parameters being in the parameter space. Values closer to to the border of the parameter space than this are considered to be "outside" the parameter space. |
Details
When the number of parameters is large, it might be better to plot a smaller number of profile
log-likelihood functions at a time using the argument which_pars
.
The red vertical line points the estimate.
Value
Only plots to a graphical device and doesn't return anything.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
get_foc
, get_soc
, diagnostic_plot
Examples
# Threshold STVAR with p=1, M=2, the first lag of the second variable as switching variable:
pars <- c(0.5231, 0.1015, 1.9471, 0.3253, 0.3476, 0.0649, -0.035, 0.7513, 0.1651,
-0.029, -0.7947, 0.7925, 0.4233, 5e-04, 0.0439, 1.2332, -0.0402, 0.1481, 1.2036)
mod12thres <- STVAR(data=gdpdef, p=1, M=2, params=pars, weight_function="threshold",
weightfun_pars=c(2, 1))
# Plot the profile log-likelihood functions of all parameters:
profile_logliks(mod12thres, precision=50) # Plots fast with precision=50
# Plot only the profile log-likelihood function of the threshold parameter
# (which is the last parameter in the parameter vector):
profile_logliks(mod12thres, which_pars=length(pars), precision=100)
# Plot only the profile log-likelihood functions of the intercept parameters
# (which are the first four parameters in the parameter vector, as d=2 and M=2):
profile_logliks(mod12thres, which_pars=1:4, precision=100)
Create random VAR model (dxd)
coefficient matrices A
.
Description
random_coefmats
generates random VAR model coefficient matrices.
Usage
random_coefmats(d, how_many, scale)
Arguments
how_many |
how many |
scale |
non-diagonal elements will be drawn from mean zero normal distribution
with |
Value
Returns ((how_many*d^2)x1)
vector containing vectorized coefficient
matrices (vec(A_{1}),...,vec(A_{how_many}))
. Note that if how_many==p
,
then the returned vector equals \phi_{m}
.
Create random stationary VAR model (dxd)
coefficient matrices A
.
Description
random_coefmats2
generates random VAR model coefficient matrices.
Usage
random_coefmats2(p, d, ar_scale = 1)
Arguments
p |
a positive integer specifying the autoregressive order |
ar_scale |
a positive real number. Larger values will typically result larger AR coefficients. |
Details
The coefficient matrices are generated using the algorithm proposed by Ansley
and Kohn (1986) which forces stationarity. It's not clear in detail how ar_scale
affects the coefficient matrices. Read the cited article by Ansley and Kohn (1986) and
the source code for more information.
Note that when using large ar_scale
with large p
or d
, numerical
inaccuracies caused by the imprecision of the float-point presentation may result in errors
or nonstationary AR-matrices. Using smaller ar_scale
facilitates the usage of larger
p
or d
.
Value
Returns ((pd^2)x1)
vector containing stationary vectorized coefficient
matrices (vec(A_{1}),...,vec(A_{p})
.
References
Ansley C.F., Kohn R. 1986. A note on reparameterizing a vector autoregressive moving average model to enforce stationarity. Journal of statistical computation and simulation, 24:2, 99-106.
Create random VAR model error term covariance matrix
Description
random_covmat
generates random VAR model (dxd)
error term covariance matrix \Omega
from (scaled) Wishart distribution.
Usage
random_covmat(d, omega_scale)
Arguments
omega_scale |
a size |
Value
Returns a (d(d+1)/2x1)
vector containing vech-vectorized covariance matrix
\Omega
.
Create random distribution parameter values
Description
random_distpars
generates random distribution parameter values
Usage
random_distpars(d, cond_dist)
Arguments
cond_dist |
specifies the conditional distribution of the model as |
Value
Returns a numeric vector ...
- If
cond_dist == "Gaussian"
: of length zero.
- If
cond_dist == "Student"
: of length one containing a df param strictly larger than two.
- If
cond_dist == "ind_Student"
: of length d containing df params strictly larger than two.
- If
cond_dist == "ind_skewed_t"
: of length 2d containing df params strictly larger than two in the first d elements and skewness params strictly between -1 and 1 in the rest d elements.
Create random VAR model impact matrix
Description
random_impactmat
generates random VAR model (dxd)
impact matrix B
with its elements drawn from specific normal distributions (see the source code). If not the first
regime, will create the matrix B_m*
.
Usage
random_impactmat(d, B_scale, is_regime1 = TRUE)
Arguments
B_scale |
a size |
is_regime1 |
is the impact matrix for Regime 1? Regime 1 impact matrix is constrained so the elements in its first row are in a decreasing ordering and the diagonal elements are strictly positive. |
Details
If the impact matrix is not for Regime 1, will create the matrix B_m*
, which is related
to the impact matrix B_m
of Regime m as B_m* = B_m - B_1
.
Value
Returns a (d^2 \times 1)
vector containing the vectorized impact matrix B
.
Create random mean parametrized parameter vector
Description
random_ind
generates random mean parametrized parameter vector.
Usage
random_ind(
p,
M,
d,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
force_stability = is.null(AR_constraints),
mu_scale,
mu_scale2,
omega_scale,
B_scale,
weight_scale,
ar_scale = 1,
ar_scale2 = 1,
fixed_params = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
force_stability |
Should the algorithm proposed by Ansley and Kohn (1986) be used to generate AR matrices that always satisfy the stability condition? Not supported if AR constraints are employed. |
mu_scale |
a size |
mu_scale2 |
a size |
omega_scale |
a size |
B_scale |
a size |
weight_scale |
For...
|
ar_scale |
a positive real number between zero and one adjusting how large AR parameter values are typically
proposed in construction of the initial population: larger value implies larger coefficients (in absolute value).
After construction of the initial population, a new scale is drawn from |
ar_scale2 |
a positive real number adjusting how large AR parameter values are typically proposed in some random mutations (if AR constraints are employed, in all random mutations): larger value implies smaller coefficients (in absolute value). Values larger than 1 can be used if the AR coefficients are expected to be very small. If set smaller than 1, be careful as it might lead to failure in the creation of parameter candidates that satisfy the stability condition. |
fixed_params |
a vector containing fixed parameter values for intercept, autoregressive, and weight parameters
that should be fixed in the initial population. Should have the form:
For models with...
Note that |
Details
Structural models are not supported!
Value
Returns random mean parametrized parameter vector that has the same form as the argument params
in the other functions, for instance, in the function loglikelihood
.
References
Ansley C.F., Kohn R. 1986. A note on reparameterizing a vector autoregressive moving average model to enforce stationarity. Journal of statistical computation and simulation, 24:2, 99-106.
Create random transition weight parameter values
Description
random_weightpars
generates random transition weight parameter values
Usage
random_weightpars(
M,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
weight_scale
)
Arguments
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
weight_scale |
For...
|
Value
Returns a numeric vector ...
- If
weight_function == "relative_dens"
: a length
M-1
vector(\alpha_1,...,\alpha_{M-1})
.- If
weight_function == "logistic"
: a length two vector
(c,\gamma)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.- If
weight_function == "mlogit"
: a length
((M-1)k\times 1)
vector(\gamma_1,...,\gamma_{M-1})
, where\gamma_m
(k\times 1)
,m=1,...,M-1
contains the mlogit-regression coefficients of them
th regime. Specifically, for switching variables with indices inI\subset\lbrace 1,...,d\rbrace
, and with\tilde{p}\in\lbrace 1,...,p\rbrace
lags included,\gamma_m
contains the coefficients for the vectorz_{t-1} = (1,\tilde{z}_{\min\lbrace I\rbrace},...,\tilde{z}_{\max\lbrace I\rbrace})
, where\tilde{z}_{i} =(y_{it-1},...,y_{it-\tilde{p}})
,i\in I
. Sok=1+|I|\tilde{p}
where|I|
denotes the number of elements inI
.- If
weight_function == "exponential"
: a length two vector
(c,\gamma)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.- If
weight_function == "threshold"
: a length
M-1
vector(r_1,...,r_{M-1})
, wherer_1,...,r_{M-1}
are the threshold values in an increasing order.- If
weight_function == "exogenous"
: of length zero.
In the decomposition of the covariance matrices (Muirhead, 1982, Theorem A9.9), change the ordering of the covariance matrices.
Description
redecompose_Omegas
exchanges the order of the covariance matrices in
the decomposition of Muirhead (1982, Theorem A9.9) and returns the new decomposition.
Usage
redecompose_Omegas(M, d, W, lambdas, perm = 1:M)
Arguments
M |
the number of regimes in the model |
d |
the number of time series in the system |
W |
a length |
lambdas |
a length |
perm |
a vector of length |
Details
We consider the following decomposition of positive definite covariannce matrices:
\Omega_1 = WW'
, \Omega_m = W\Lambda_{m}W'
, m=2,..,M
where
\Lambda_{m} = diag(\lambda_{m1},...,\lambda_{md})
contains the strictly postive eigenvalues of
\Omega_m\Omega_1^{-1}
and the column of the invertible W
are the corresponding eigenvectors.
Note that this decomposition does not necessarily exists for M > 2
.
See Muirhead (1982), Theorem A9.9 for more details on the decomposition and the source code for more details on the reparametrization.
Value
Returns a d^2 + (M - 1)d \times 1
vector of the form c(vec(new_W), new_lambdas)
where the lambdas parameters are in the regimewise order (first regime 2, then 3, etc) and the
"new W" and "new lambdas" are constitute the new decomposition with the order of the covariance
matrices given by the argument perm
. Notice that if the first element of perm
is one, the W matrix will be the same and the lambdas are just re-ordered.
Note that unparametrized zero elements ARE present in the returned W!
Warning
No argument checks! Does not work with dimension d=1
or with only
one mixture component M=1
.
References
Muirhead R.J. 1982. Aspects of Multivariate Statistical Theory, Wiley.
Examples
# Create two (2x2) coviance matrices:
d <- 2 # The dimension
M <- 2 # The number of covariance matrices
Omega1 <- matrix(c(2, 0.5, 0.5, 2), nrow=d)
Omega2 <- matrix(c(1, -0.2, -0.2, 1), nrow=d)
# The decomposition with Omega1 as the first covariance matrix:
decomp1 <- diag_Omegas(Omega1, Omega2)
W <- matrix(decomp1[1:d^2], nrow=d, ncol=d) # Recover W
lambdas <- decomp1[(d^2 + 1):length(decomp1)] # Recover lambdas
tcrossprod(W) # = Omega1
W%*%tcrossprod(diag(lambdas), W) # = Omega2
# Reorder the covariance matrices in the decomposition so that now
# the first covariance matrix is Omega2:
decomp2 <- redecompose_Omegas(M=M, d=d, W=as.vector(W), lambdas=lambdas,
perm=2:1)
new_W <- matrix(decomp2[1:d^2], nrow=d, ncol=d) # Recover W
new_lambdas <- decomp2[(d^2 + 1):length(decomp2)] # Recover lambdas
tcrossprod(new_W) # = Omega2
new_W%*%tcrossprod(diag(new_lambdas), new_W) # = Omega1
Reform constrained parameter vector into the "standard" form
Description
reform_constrained_pars
reforms constrained parameter vector
into the form that corresponds to unconstrained parameter vectors.
Usage
reform_constrained_pars(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
other_constraints = NULL,
change_na = FALSE
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
other_constraints |
A list containing internally used additional type of constraints (see the options below).
|
change_na |
change NA parameter values of constrained models to -9.999? |
Value
Returns "regular model" parameter vector corresponding to the constraints.
Warning
No argument checks!
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Reform data
Description
reform_data
reforms the data into a form that is
easier to use when calculating log-likelihood values etc.
Usage
reform_data(data, p)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
Details
Assumes the observed data is y_{-p+1},...,y_0,y_1,...,y_{T}
.
Value
Returns the data reformed into a ((n_{obs}-p+1)\times dp)
matrix. The i:th row
of the matrix contains the vector (y_{i-1},...,y_{i-p})
(dp\times 1)
, where
y_{i}=(y_{1i},...,y_{di})
(d \times 1)
.
Warning
No argument checks!
Calculate "distance" between two (scaled) regimes
\upsilon_{m}
= (\phi_{m},
\phi_{m}
,\sigma_{m})
Description
regime_distance
calculates "distance" between two scaled regimes.
Usage
regime_distance(regime_pars1, regime_pars2)
Arguments
regime_pars1 |
a length |
regime_pars2 |
a length |
Value
Returns "distance" between regime_pars1
and regime_pars2
. Values are scaled
before calculating the "distance". Read the source code for more details.
Warning
No argument checks!
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Reorder columns of impact matrix B of a structural STVAR model that is identified by heteroskedasticity or non-Gaussianity.
Description
reorder_B_columns
reorder columns of impact matrix B of a structural STVAR model that is
identified by heteroskedasticity or non-Gaussianity. For models identified by heteroskedasticity, also the
lambda parameters are reordered accordingly. For models with ind Student or skewed t shocks, also the degrees
of freedom and skewness parameters (latter for skewed t) are reordered accordingly.
Usage
reorder_B_columns(stvar, perm, calc_std_errors = FALSE)
Arguments
stvar |
a class 'stvar' object defining a structural STVAR model that is identified by heteroskedasticity
or non-Gaussianity, typically created with |
perm |
an integer vector of length
|
calc_std_errors |
should approximate standard errors be calculated? |
Details
The order of the columns of the impact matrix can be changed without changing the implied reduced
form model (as long as, for models identified by heteroskedasticity, the order of lambda parameters is also changed accordingly;
and for model identified by non-Gaussianity, ordering of the columns of all the impact matrices and the component specific
distribution parameters is also changed accordingly). Note that constraints imposed on the impact matrix via B_constraints
will also be modified accordingly.
Also all signs in any column of impact matrix can be swapped (without changing the implied reduced form model, as long as signs of
any skewness parameters are also swapped accordingly) with the function swap_B_signs
. This obviously also swaps the sign constraints
(if any) in the corresponding columns of the impact matrix.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
References
Lütkepohl H., Netšunajev A. 2018. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
See Also
Examples
# Create a structural two-variate Student's t STVAR p=2, M=2 model with logistic transition
# weights and the first lag of the second variable as the switching variable, and shocks
# identified by heteroskedasticity:
theta_222logt <- c(0.356914, 0.107436, 0.356386, 0.086330, 0.139960, 0.035172, -0.164575,
0.386816, 0.451675, 0.013086, 0.227882, 0.336084, 0.239257, 0.024173, -0.021209, 0.707502,
0.063322, 0.027287, 0.009182, 0.197066, -0.03, 0.24, -0.76, -0.02, 3.36, 0.86, 0.1, 0.2, 7)
mod222logt <- STVAR(p=2, M=2, d=2, params=theta_222logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="heteroskedasticity")
# Print the parameter values, W and lambdas are printed in the bottom:
mod222logt
# Reverse the ordering of the columns of W (or equally the impact matrix):
mod222logt_rev <- reorder_B_columns(mod222logt, perm=c(2, 1))
mod222logt_rev # The columns of the impact matrix are in a reversed order
# Swap the ordering of the columns of the impact matrix back to the original:
mod222logt_rev2 <- reorder_B_columns(mod222logt_rev, perm=c(2, 1))
mod222logt_rev2 # The columns of the impact matrix are back in the original ordering
# Below code does not do anything, as perm=1:2, so the ordering does not change:
mod222logt3 <- reorder_B_columns(mod222logt, perm=c(1, 2))
mod222logt3 # The ordering of the columns did not change from the original
Simulate method for class 'stvar' objects
Description
simulate.stvar
is a simulate method for class 'stvar' objects.
Usage
## S3 method for class 'stvar'
simulate(
object,
nsim = 1,
seed = NULL,
...,
init_values = NULL,
init_regime,
ntimes = 1,
use_stat_for_Gaus = FALSE,
burn_in = 1000,
exo_weights = NULL,
drop = TRUE
)
Arguments
object |
an object of class |
nsim |
number of observations to be simulated. |
seed |
set seed for the random number generator? |
... |
currently not in use. |
init_values |
a size |
init_regime |
an integer in |
ntimes |
how many sets of simulations should be performed? |
use_stat_for_Gaus |
if |
burn_in |
Burn-in period for simulating initial values from a regime when |
exo_weights |
if |
drop |
if |
Details
When using init_regime
to simulate the initial values from a given regime, we employ the following simulation
procedure to obtain the initial values (unless use_stat_for_Gaus=TRUE
and Gaussian model is considered).
First, we set the initial values to the unconditional mean of the specified regime. Then,
we simulate a large number observations from that regime as specified in the argument burn_in
. Then, we simulate
p + 100
observations more after the burn in period, and for the 100
observations calculate the transition
weights for them and take the consecutive p
observations that yield the highest transition weight for the given regime.
For models with exogenous transition weights, takes just the last p
observations after the burn-in period.
The argument ntimes
is intended for forecasting, which is used by the predict method (see ?predict.stvar
).
Value
Returns a list containing the simulation results. If drop==TRUE
and ntimes==1
(default),
contains the following entries:
sample |
a size ( |
transition weights: |
a size ( |
Otherwise, returns a list with the following entries:
$sample |
a size ( |
$transition_weights |
a size ( |
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
predict.stvar
,GIRF
, GFEVD
, fitSTVAR
,
fitSSTVAR
STVAR
Examples
# Gaussian STVAR(p=2, M=2) model with weighted relative stationary densities
# of the regimes as the transition weight function:
theta_222relg <- c(0.356914, 0.107436, 0.356386, 0.08633, 0.13996, 0.035172,
-0.164575, 0.386816, 0.451675, 0.013086, 0.227882, 0.336084, 0.239257, 0.024173,
-0.021209, 0.707502, 0.063322, 0.027287, 0.009182, 0.197066, 0.205831, 0.005157,
0.025877, 1.092094, -0.009327, 0.116449, 0.592446)
mod222relg <- STVAR(data=gdpdef, p=2, M=2, d=2, params=theta_222relg,
weight_function="relative_dens")
# Simulate T=200 observations using given initial values:
init_vals <- matrix(c(0.5, 1.0, 0.5, 1), nrow=2)
sim1 <- simulate(mod222relg, nsim=200, seed=1, init_values=init_vals)
plot.ts(sim1$sample) # Sample
plot.ts(sim1$transition_weights) # Transition weights
# Simulate T=100 observations, with initial values drawn from the stationary
# distribution of the 1st regime:
sim2 <- simulate(mod222relg, nsim=200, seed=1, init_regime=1)
plot.ts(sim2$sample) # Sample
plot.ts(sim2$transition_weights) # Transition weights
# Logistic Student's t STVAR with p=1, M=2, and the first lag of the second variable
# as the switching variable.
params12 <- c(0.62906848, 0.14245295, 2.41245785, 0.66719269, 0.3534745, 0.06041779, -0.34909745,
0.61783824, 0.125769, -0.04094521, -0.99122586, 0.63805416, 0.371575, 0.00314754, 0.03440824,
1.29072533, -0.06067807, 0.18737385, 1.21813844, 5.00884263, 7.70111672)
fit12 <- STVAR(data=gdpdef, p=1, M=2, params=params12, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student")
# Simulate T=100 observations with initial values drawn from the second regime.
# Since the stationary distribution of the Student's regime is not known, we
# use a simulation procedure that starts from the unconditional mean of the regime,
# then simulates a number of observations from the regime for a "burn-in" period,
# and finally takes the last p observations generated from the regime as the initial
# values for the simulation from the STVAR model:
sim3 <- simulate(fit12, nsim=100, init_regime=1, burn_in=1000)
plot.ts(sim3$sample) # Sample
plot.ts(sim3$transition_weights) # Transition weights
Simulate observations from a regime of a STVAR model
Description
simulate_from_regime
allows to simulate observations from a single
regime of a STVAR model
Usage
simulate_from_regime(
stvar,
regime = 1,
nsim = 1,
init_values = NULL,
use_transweights = TRUE
)
Arguments
stvar |
an object of class |
regime |
an integer in |
nsim |
number of observations to be simulated. |
init_values |
a size |
use_transweights |
if |
Details
Does not take random number generator seed as an argument to avoid unwanted behavior,
because simulate_from_regime
is mostly called from simulate.stvar
that takes a seed as its argument, and simulate_from_regime
calls simulate.stvar
to simulate the observations.
Specifically, simulate_from_regime
generates a STVAR model from the given regime, sets up the initial values to the
(if not specified), and then calls simulate.stvar
accordingly.
Value
- If
use_transweights=FALSE
: Returns a
(nsim \times d)
matrix such that thet
th row contains thet
th simulated observation.- If
use_transweights=TRUE
: Returns a
(p \times d)
such that thet
th row constrains thet
th observations.
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
INTERNAL Simulate method for class 'stvar' objects
Description
simulate_stvar_int
is an internal simulate function for class 'stvar' objects.
Usage
simulate_stvar_int(
object,
nsim = 1,
seed = NULL,
...,
init_values = NULL,
init_regime,
ntimes = 1,
use_stat_for_Gaus = FALSE,
burn_in = 1000,
exo_weights = NULL,
drop = TRUE,
girf_pars = NULL
)
Arguments
object |
an object of class |
nsim |
number of observations to be simulated. |
seed |
set seed for the random number generator? |
... |
currently not in use. |
init_values |
a size |
init_regime |
an integer in |
ntimes |
how many sets of simulations should be performed? |
use_stat_for_Gaus |
if |
burn_in |
Burn-in period for simulating initial values from a regime when |
exo_weights |
if |
drop |
if |
girf_pars |
This argument is used internally in the estimation of generalized impulse response functions. Specifying something else than null to it will change how the function behaves. Should be a list with following elements
|
Details
When using init_regime
to simulate the initial values from a given regime, we employ the following simulation
procedure to obtain the initial values (unless use_stat_for_Gaus=TRUE
and Gaussian model is considered).
First, we set the initial values to the unconditional mean of the specified regime. Then,
we simulate a large number observations from that regime as specified in the argument burn_in
. Then, we simulate
p + 100
observations more after the burn in period, and for the 100
observations calculate the transition
weights for them and take the consecutive p
observations that yield the highest transition weight for the given regime.
For models with exogenous transition weights, takes just the last p
observations after the burn-in period.
The argument ntimes
is intended for forecasting, which is used by the predict method (see ?predict.stvar
).
Value
Returns a list containing the simulation results. If drop==TRUE
and ntimes==1
(default),
contains the following entries:
sample |
a size ( |
transition weights: |
a size ( |
Otherwise, returns a list with the following entries:
$sample |
a size ( |
$transition_weights |
a size ( |
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.
Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
See Also
predict.stvar
,GIRF
, GFEVD
, fitSTVAR
,
fitSSTVAR
STVAR
The density function of the univariate skewed t distribution
Description
skewed_t_dens
calculates the density of the univariate skewed t distribution described in Hansen (1994).
Usage
skewed_t_dens(y, nu, lambda)
Arguments
y |
a numeric vector containing the values at which the density is to be evaluated. |
nu |
the degrees of freedom parameter value, a numeric scalar strictly larger than two. |
lambda |
the skewness parameter value, a numeric scalar strictly between -1 and 1. |
Details
See Hansen (1994, Section 2.4) for the details of the skewed t distribution.
Value
Returns a numeric vector of the same length as y
containing the density values.
References
Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.
Create random VAR model (dxd)
error term covariance matrix \Omega
fairly close to the given positive definite covariance matrix using (scaled)
Wishart distribution
Description
smart_covmat
generates random VAR model (dxd)
error term covariance matrix \Omega
from (scaled) Wishart distribution that is fairly close to the given matrix.
Usage
smart_covmat(d, Omega, accuracy)
Arguments
Omega |
a symmetric positive definite |
accuracy |
a positive real number adjusting how close to the given covariance matrix the returned individual should be. The standard deviation of each diagonal element is...
Wishart distribution is used for reduced form models, but for more details read the source code. |
Value
Returns a (d(d+1)/2x1)
vector containing vech-vectorized covariance matrix
\Omega
.
Create random distribution parameter values close to given values
Description
smart_distpars
generates random degrees of freedom parameter values
close to given values.
Usage
smart_distpars(distpars, accuracy, cond_dist)
Arguments
distpars |
the old distribution parameters (of all regimes) |
accuracy |
a positive real number adjusting how close to the given distribution parameters the returned values should be. |
Value
Returns a numeric vector ...
- If
cond_dist == "Gaussian"
: of length zero.
- If
cond_dist == "Student"
: of length one containing a degrees of freedom parameter value (strictly larger than two).
- If
cond_dist == "ind_Student"
: of length d containing a degrees of freedom parameter values (strictly larger than two).
- If
cond_dist == "ind_skewed_t"
: of length 2d containing df params strictly larger than two in the first d elements and skewness params strictly between -1 and 1 in the rest d elements.
Create a random VAR model (dxd)
error impact matrix B
fairly close to the given invertible impact matrix.
Description
smart_impactmat
generates a random VAR model (dxd)
error impact matrix B
fairly close to the given invertible impact matrix.
Usage
smart_impactmat(d, B, accuracy, is_regime1 = TRUE)
Arguments
B |
an invertible |
accuracy |
a positive real number adjusting how close to the given impact matrix the returned individual should be. Larger value implies higher accuracy. |
is_regime1 |
is the impact matrix for Regime 1? Regime 1 impact matrix is constrained so the elements in its first row are in a decreasing ordering and the diagonal elements are strictly positive. |
Value
Returns a (d^2 \times 1)
vector containing the vectorized impact matrix B
.
Create random parameter vector that is fairly close to a given parameter vector
Description
smart_ind
creates random mean parametrized parameter vector that is
model fairly close to a given parameter vector. The result may not be satisfy the stability
condition.
Usage
smart_ind(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
accuracy = 1,
which_random = numeric(0),
mu_scale,
mu_scale2,
omega_scale,
B_scale,
ar_scale = 1,
ar_scale2 = 1,
fixed_params = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
accuracy |
a positive real number adjusting how close to the given parameter vector the returned individual should be. Larger number means larger accuracy. Read the source code for details. |
which_random |
a vector with length between 1 and M specifying the mixture components that should be random instead of close to the given parameter vector. This does not consider constrained AR or lambda parameters. |
mu_scale |
a size |
mu_scale2 |
a size |
omega_scale |
a size |
B_scale |
a size |
ar_scale |
a positive real number between zero and one adjusting how large AR parameter values are typically
proposed in construction of the initial population: larger value implies larger coefficients (in absolute value).
After construction of the initial population, a new scale is drawn from |
ar_scale2 |
a positive real number adjusting how large AR parameter values are typically proposed in some random mutations (if AR constraints are employed, in all random mutations): larger value implies smaller coefficients (in absolute value). Values larger than 1 can be used if the AR coefficients are expected to be very small. If set smaller than 1, be careful as it might lead to failure in the creation of parameter candidates that satisfy the stability condition. |
fixed_params |
a vector containing fixed parameter values for intercept, autoregressive, and weight parameters
that should be fixed in the initial population. Should have the form:
For models with...
Note that |
Details
Structural models are not supported!
Value
Returns random mean parametrized parameter vector that has the same form as the argument params
in the other functions, for instance, in the function loglikelihood
.
References
Ansley C.F., Kohn R. 1986. A note on reparameterizing a vector autoregressive moving average model to enforce stationarity. Journal of statistical computation and simulation, 24:2, 99-106.
Create random transition weight parameter values
Description
smart_weightpars
generates random transition weight parameter values
relatively close to the ones given in weight_pars
Usage
smart_weightpars(
M,
weight_pars,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weight_constraints = NULL,
accuracy
)
Arguments
M |
a positive integer specifying the number of regimes |
weight_pars |
a vector containing transition weight parameter values.
|
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weight_constraints |
a list of two elements, |
accuracy |
a positive real number adjusting how close to the given parameter vector the returned individual should be. Larger number means larger accuracy. Read the source code for details. |
Value
Returns a numeric vector ...
- If
weight_function == "relative_dens"
: a length
M-1
vector(\alpha_1,...,\alpha_{M-1})
.- If
weight_function == "logistic"
: a length two vector
(c,\gamma)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.- If
weight_function == "mlogit"
: a length
((M-1)k\times 1)
vector(\gamma_1,...,\gamma_{M-1})
, where\gamma_m
(k\times 1)
,m=1,...,M-1
contains the mlogit-regression coefficients of them
th regime. Specifically, for switching variables with indices inI\subset\lbrace 1,...,d\rbrace
, and with\tilde{p}\in\lbrace 1,...,p\rbrace
lags included,\gamma_m
contains the coefficients for the vectorz_{t-1} = (1,\tilde{z}_{\min\lbrace I\rbrace},...,\tilde{z}_{\max\lbrace I\rbrace})
, where\tilde{z}_{i} =(y_{it-1},...,y_{it-\tilde{p}})
,i\in I
. Sok=1+|I|\tilde{p}
where|I|
denotes the number of elements inI
.- If
weight_function == "exponential"
: a length two vector
(c,\gamma)
, wherec\in\mathbb{R}
is the location parameter and\gamma >0
is the scale parameter.- If
weight_function == "threshold"
: a length
M-1
vector(r_1,...,r_{M-1})
, wherer_1,...,r_{M-1}
are the threshold values in an increasing order.- If
weight_function == "exogenous"
: of length zero.
Sort and sign change the columns of the impact matrices of the regimes so that the first element in each column of B_1
is positive and in a decreasing order.
Description
sort_impactmats
sorts and sign changes the columns of the impact matrices of the regimes so that the first element
in each column of B_1
is positive and in a decreasing order. The same reordering and sign changes performed to the columns of
B_1
are applied to the rest of the impact matrices to obtain an observationally equivalent model. For skewed t models, also
the signs of the skewness parameters corresponding to the columns whose signs are changed are changed accordingly.
Usage
sort_impactmats(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
Details
This function is internally used by GAfit
and fitSTVAR
, so structural models or B_constraints
are not supported.
Value
Returns sorted parameter vector of the form described for the argument params
,
with the regimes sorted so that...
- If
cond_dist == "ind_Student"
: The parameter vector with the columns of the impact matrices sorted and sign changed so that the first element in each column of
B_1
is positive and in a decreasing order. Sorts also the degrees of freedom parameters accordingly.- If
cond_dist == "ind_skewed_t"
: The parameter vector with the columns of the impact matrices sorted so that the first element in each column of
B_1
are in a decreasing order. Also sorts the degrees of freedom and skewness parameters accordingly. Moreover, if signs of any column are changed, the signs of the corresponding skewness parameter values are also changed accordingly.- Otherwise:
Nothing to sort, so returns the original parameter vector given in
param
.
Sort regimes in parameter vector according to transition weights into a decreasing order
Description
sort_regimes
sorts regimes in the parameter vector according to
the transition weight parameters.
Usage
sort_regimes(
p,
M,
d,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
B_constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
B_constraints |
a |
Details
Constrained parameter vectors are not supported (except B_constraints
for structural models identified
by heteroskedasticity).
Value
Returns sorted parameter vector of the form described for the argument params
,
with the regimes sorted so that...
- If
weight_function == "relative_dens"
: \alpha_{1}>...>\alpha_{M}
.- If
weight_function == "logistic"
: Nothing to sort, so returns the original parameter vector given in
param
.- If
weight_function == "mlogit"
: Does not currently sort, so returns the original parameter vector given in
param
.- If
weight_function == "exponential"
: Nothing to sort, so returns the original parameter vector given in
param
.- If
weight_function == "threshold"
: The increasing ordering of the thresholds is imposed in the parameter space, so nothing to sort and thereby returns the original parameter vector given in
param
.- If
weight_function == "exogenous"
: Does not sort but returns the original parameter vector.
Check the stability condition for each of the regimes
Description
stab_conds_satisfied
checks whether the stability condition is satisfied
for each of the regimes.
Usage
stab_conds_satisfied(p, M, d, params, all_boldA = NULL, tolerance = 0.001)
Arguments
p |
the autoregressive order of the model |
M |
the number of regimes |
d |
the number of time series in the system, i.e., the dimension |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
all_boldA |
3D array containing the |
tolerance |
Returns |
Details
Does not support constrained parameter vectors.
Value
Returns TRUE
if the stability condition is satisfied for all regimes and FALSE
if not.
According to the argument tolerance
, stab_conds_satisfied
may return FALSE
when the parameter
vector satisfies the stability conditions but is very close to the boundary (this is used to ensure numerical stability
in the estimation of the model parameters).
Warning
No argument checks!
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
The density function of the univariate t distribution with zero mean and unit variance
Description
stand_t_dens
calculates the density of the univariate t distribution with zero mean and unit variance,
described, for example, in Virolainen (2025).
Usage
stand_t_dens(y, nu)
Arguments
y |
a numeric vector containing the values at which the density is to be evaluated. |
nu |
the degrees of freedom parameter value, a numeric scalar strictly larger than two. |
Details
See Virolainen (2025) and the references therein, for example, for the details of the density function of t-distribution with zero mean and unit variance (assume the skewness parameter value is zero to obtain the non-skewed version of the t-distribution).
Value
Returns a numeric vector of the same length as y
containing the density values.
References
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
Calculate standard errors for estimates of a smooth transition VAR model
Description
standard_errors
calculates approximate standard errors for the smooth transition
VAR model using square roots of the diagonal of inverse of observed information matrix
and central-difference approximation for the differentiation.
Usage
standard_errors(
data,
p,
M,
params,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
identification = c("reduced_form", "recursive", "heteroskedasticity",
"non-Gaussianity"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
B_constraints = NULL,
penalized = FALSE,
penalty_params = c(0.05, 0.2),
allow_unstab = FALSE,
minval
)
Arguments
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
params |
a real valued vector specifying the parameter values.
Should have the form
For models with...
Above, |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
identification |
is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
B_constraints |
a |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
minval |
the value that will be returned if the parameter vector does not lie in the parameter space (excluding the identification condition). |
Details
This function assumes the standard asymptotic distribution of the estimator
Value
A vector containing the approximate standard errors of the estimates.
References
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
@keywords internal
Update STVAR model estimated with a version of the package <1.1.0 to be compatible with the versions >=1.1.0.
Description
update_stvar_to_sstvar110
updates a STVAR model estimated with a version of
the package <1.1.0 to be compatible with the versions >=1.1.0 by adding the elements
$penalized
, $penalty_params
, and $allow_unstab
to the model object.
Usage
stvar_to_sstvars110(stvar)
Arguments
stvar |
object of class |
Details
The function is useful when a STVAR model estimated with a version of the package <1.1.0.
Does not do anything if the elements $penalized
, $penalty_params
, and $allow_unstab
are already containing in the model object.
Value
Returns an object of class 'stvar'
with the elements $penalized
,
$penalty_params
, and $allow_unstab
added to it if they were missing.
Examples
# Linear Gaussian VAR(p=1) model:
theta_112 <- c(0.649526, 0.066507, 0.288526, 0.021767, -0.144024, 0.897103,
0.601786, -0.002945, 0.067224)
mod112 <- STVAR(data=gdpdef, p=1, M=1, params=theta_112)
# Update to include the new elements (does not do anything if they are already
# included):
mod112 <- stvar_to_sstvars110(mod112)
Swap all signs in pointed columns of the impact matrix of a structural STVAR model that is identified by heteroskedasticity or non-Gaussianity
Description
swap_B_signs
swaps all signs in pointed columns of the impact matrix of
a structural STVAR model that is identified by heteroskedasticity or non-Gaussianity. For ind skewed t
models, also the signs of the skewness parameters are swapped accordingly.
Usage
swap_B_signs(stvar, which_to_swap, calc_std_errors = FALSE)
Arguments
stvar |
a class 'stvar' object defining a structural STVAR model that is identified by heteroskedasticity
or non-Gaussianity, typically created with |
which_to_swap |
a numeric vector of length at most |
calc_std_errors |
should approximate standard errors be calculated? |
Details
All signs in any column of the impact matrix can be swapped without changing the implied reduced form model,
but for ind skewed t models, also the signs of the corresponding skewness parameter values need to be swapped.
For model identified by non-Gaussianity, the signs of the columns of the impact matrices of all the regimes are
swapped accordingly. Note that the sign constraints imposed on the impact matrix via B_constraints
are also
swapped in the corresponding columns accordingly.
Also the order of the columns of the impact matrix can be changed (without changing the implied reduced
form model) as long as the ordering of other related parameters is also changed accordingly. This can be
done with the function reorder_B_columns
.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
References
Lütkepohl H., Netšunajev A. 2018. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
See Also
GIRF
, fitSSTVAR
, reorder_B_columns
Examples
# Create a structural two-variate Student's t STVAR p=2, M=2, model with logistic transition
# weights and the first lag of the second variable as the switching variable, and shocks
# identified by heteroskedasticity:
theta_222logt <- c(0.356914, 0.107436, 0.356386, 0.086330, 0.139960, 0.035172, -0.164575,
0.386816, 0.451675, 0.013086, 0.227882, 0.336084, 0.239257, 0.024173, -0.021209, 0.707502,
0.063322, 0.027287, 0.009182, 0.197066, -0.03, 0.24, -0.76, -0.02, 3.36, 0.86, 0.1, 0.2, 7)
mod222logt <- STVAR(p=2, M=2, d=2, params=theta_222logt, weight_function="logistic",
weightfun_pars=c(2, 1), cond_dist="Student", identification="heteroskedasticity")
# Print the parameter values, W and lambdas are printed in the bottom:
mod222logt
# Swap the signs of the first column of W (or equally the impact matrix):
mod222logt2 <- swap_B_signs(mod222logt, which_to_swap=1)
mod222logt2 # The signs of the first column of the impact matrix are swapped
# Swap the signs of the second column of the impact matrix:
mod222logt3 <- swap_B_signs(mod222logt, which_to_swap=2)
mod222logt3 # The signs of the second column of the impact matrix are swapped
# Swap the signs of both columns of the impact matrix:
mod222logt4 <- swap_B_signs(mod222logt, which_to_swap=1:2)
mod222logt4 # The signs of both columns of the impact matrix are swapped
Swap the parametrization of a STVAR model
Description
swap_parametrization
swaps the parametrization of a STVAR model
to "mean"
if the current parametrization is "intercept"
, and vice versa.
Usage
swap_parametrization(stvar, calc_std_errors = FALSE)
Arguments
stvar |
object of class |
calc_std_errors |
should approximate standard errors be calculated? |
Details
swap_parametrization
is a convenient tool if you have estimated the model in
"intercept" parametrization but wish to work with "mean" parametrization in the future, or vice versa.
Value
Returns an S3 object of class 'stvar'
defining a smooth transition VAR model. The returned list
contains the following components (some of which may be NULL
depending on the use case):
data |
The input time series data. |
model |
A list describing the model structure. |
params |
The parameters of the model. |
std_errors |
Approximate standard errors of the parameters, if calculated. |
transition_weights |
The transition weights of the model. |
regime_cmeans |
Conditional means of the regimes, if data is provided. |
total_cmeans |
Total conditional means of the model, if data is provided. |
total_ccovs |
Total conditional covariances of the model, if data is provided. |
uncond_moments |
A list of unconditional moments including regime autocovariances, variances, and means. |
residuals_raw |
Raw residuals, if data is provided. |
residuals_std |
Standardized residuals, if data is provided. |
structural_shocks |
Recovered structural shocks, if applicable. |
loglik |
Log-likelihood of the model, if data is provided. |
IC |
The values of the information criteria (AIC, HQIC, BIC) for the model, if data is provided. |
all_estimates |
The parameter estimates from all estimation rounds, if applicable. |
all_logliks |
The log-likelihood of the estimates from all estimation rounds, if applicable. |
which_converged |
Indicators of which estimation rounds converged, if applicable. |
which_round |
Indicators of which round of optimization each estimate belongs to, if applicable. |
seeds |
The seeds used in the estimation in |
LS_estimates |
The least squares estimates of the parameters in the form
|
References
Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.
Hubrich K., Teräsvirta. T. 2013. Thresholds and Smooth Transitions in Vector Autoregressive Models. CREATES Research Paper 2013-18, Aarhus University.
Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.
Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. Econometric Reviews, 39:4, 407-414.
Lütkepohl H., Netšunajev A. 2017. Structural vector autoregressions with smooth transition in variances. Journal of Economic Dynamics & Control, 84, 43-57.
Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
Examples
## Create a Gaussian STVAR p=1, M=2 model with the weighted relative stationary densities
# of the regimes as the transition weight function; use the intercept parametrization:
theta_122relg <- c(0.734054, 0.225598, 0.705744, 0.187897, 0.259626, -0.000863,
-0.3124, 0.505251, 0.298483, 0.030096, -0.176925, 0.838898, 0.310863, 0.007512,
0.018244, 0.949533, -0.016941, 0.121403, 0.573269)
mod122 <- STVAR(p=1, M=2, d=2, params=theta_122relg, parametrization="intercept")
mod122$params[1:4] # The intercept parameters
# Swap from the intercept parametrization to mean parametrization:
mod122mu <- swap_parametrization(mod122)
mod122mu$params[1:4] # The mean parameters
# Swap back to the intercept parametrization:
mod122int <- swap_parametrization(mod122mu)
mod122int$params[1:4] # The intercept parameters
## Create a linear VAR(p=1) model with the intercept parametrization, include
# the two-variate data gdpdef to the model and calculate approximate standard errors:
theta_112 <- c(0.649526, 0.066507, 0.288526, 0.021767, -0.144024, 0.897103,
0.601786, -0.002945, 0.067224)
mod112 <- STVAR(data=gdpdef, p=1, M=1, params=theta_112, parametrization="intercept",
calc_std_errors=TRUE)
print(mod112, standard_error_print=TRUE) # Standard errors are printed for the intercepts
# To obtain standard errors for the unconditional means instead of the intercepts,
# swap to mean parametrization:
mod112mu <- swap_parametrization(mod112, calc_std_errors=TRUE)
print(mod112mu, standard_error_print=TRUE) # Standard errors are printed for the means
Reverse vectorization operator that restores zeros
Description
unWvec
forms a square matrix from a vector of
stacked columns where zeros are removed according to impact
matrix constraints.
Usage
unWvec(Wvector, d, B_constraints)
Arguments
Wvector |
a length |
d |
the number of rows in the square matrix to be formed. |
Value
a (d x d)
impact matrix W
.
Calculate the unconditional means, variances, the first p autocovariances, and the first p autocorrelations of the regimes of the model.
Description
uncond_moments
calculates the unconditional means, variances, the first p autocovariances,
and the first p autocorrelations of the regimes of the model.
Usage
uncond_moments(stvar)
Arguments
stvar |
object of class |
Value
Returns a list with three components:
$regime_means
a
M \times d
matrix vector containing the unconditional mean of the regimem
in them
th column.$regime_vars
a
M \times d
matrix vector containing the unconditional marginal variances of the regimem
in them
th column.$regime_autocovs
an
(d x d x p+1, M)
array containing the lag 0,1,...,p autocovariances of the process. The subset[, , j, m]
contains the lagj-1
autocovariance matrix (lag zero for the variance) for the regimem
.$regime_autocors
the autocovariance matrices scaled to autocorrelation matrices.
References
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.
Examples
# Two-variate Gaussian STVAR p=1, M=2 model with the weighted relative stationary
# densities of the regimes as the transition weight function:
theta_122relg <- c(0.734054, 0.225598, 0.705744, 0.187897, 0.259626, -0.000863,
-0.3124, 0.505251, 0.298483, 0.030096, -0.176925, 0.838898, 0.310863, 0.007512,
0.018244, 0.949533, -0.016941, 0.121403, 0.573269)
mod122 <- STVAR(data=gdpdef, p=1, M=2, params=theta_122relg, weight_function="relative_dens")
# Calculate the unconditional moments of model:
tmp122 <- uncond_moments(mod122)
# Print the various unconditional moments calculated:
tmp122$regime_means[,1] # Unconditional means of the first regime
tmp122$regime_means[,2] # Unconditional means of the second regime
tmp122$regime_vars[,1] # Unconditional variances of the first regime
tmp122$regime_vars[,2] # Unconditional variances of the second regime
tmp122$regime_autocovs[, , , 1] # a.cov. matrices of the first regime
tmp122$regime_autocovs[, , , 2] # a.cov. matrices of the second regime
tmp122$regime_autocors[, , , 1] # a.cor. matrices of the first regime
tmp122$regime_autocors[, , , 2] # a.cor. matrices of the second regime
# A two-variate linear Gaussian VAR p=1 model:
theta_112 <- c(0.649526, 0.066507, 0.288526, 0.021767, -0.144024, 0.897103,
0.601786, -0.002945, 0.067224)
mod112 <- STVAR(data=gdpdef, p=1, M=1, params=theta_112)
# Calculate the unconditional moments of model:
tmp112 <- uncond_moments(mod112)
# Print the various unconditional moments calculated:
tmp112$regime_means # Unconditional means
tmp112$regime_vars # Unconditional variances
tmp112$regime_autocovs # Unconditional autocovariance matrices
tmp112$regime_autocovs[, , 1, 1] # a.cov. matrix of lag zero (of the first regime)
tmp112$regime_autocovs[, , 2, 1] # a.cov. matrix of lag one (of the first regime)
tmp112$regime_autocors # Unconditional autocorrelation matrices
Reverse vectorization operator
Description
unvec
forms a square matrix from a vector of
stacked columns, stacked by vec
.
Usage
unvec(d, a)
Arguments
d |
the number of rows in the square matrix to be formed. |
a |
a size |
Value
a matrix of size (dxd)
.
Reverse operator of the parsimonious vectorization operator vech
Description
unvech
creates a symmetric matrix from the given vector by
copying the lower triangular part to be the upper triangular part as well.
Usage
unvech(d, a)
Arguments
d |
number of rows the square matrix to be formed. |
a |
a size |
Value
a symmetric matrix of size (dxd)
.
U.S. climate policy uncertainty, economic policy uncertainty, industrial production, consumer price index,
Description
A monthly U.S. data covering the period from 1987:4 to 2024:12 (453 observations) and consisting six variables. First, the climate policy uncertainty index (CPUI) (Gavridiilis, 2021), which is a news based measure of climate policy uncertainty. Second, the economic policy uncertainty index (EPUI), which is a news based measure of economic policy uncertainty, including also components quantifying the present value of future scheduled tax code expirations and disagreement among professional forecasters over future goverment purchases and consumer prices. Third, the log-difference of real indsitrial production index (IPI). Fourth, the log-difference of the consumer price index (CPI). Fifth, the log-difference of the producer price index (PPI). Sixth, an interest rate variable, which is the effective federal funds rate that is replaced by the the Wu and Xia (2016) shadow rate during zero-lower-bound periods. The Wu and Xia (2016) shadow rate is not bounded by the zero lower bound and also quantifies unconventional monetary policy measures, while it closely follows the federal funds rate when the zero lower bound does not bind. This is the dataset used in Virolainen (2025)
Usage
usacpu
Format
A numeric matrix of class 'ts'
with 443 rows and 4 columns with one time series in each column:
- First column (CPUI):
The climate policy uncertainty index, https://www.policyuncertainty.com/climate_uncertainty.html.
- Second column (EPUI):
The economic policy uncertainty index, https://www.policyuncertainty.com/us_monthly.html.
- Third column (IPI):
The log-difference of real indsitrial production index, https://fred.stlouisfed.org/series/INDPRO.
- Fourth column (CPI):
The log-difference of the consumer price index, https://fred.stlouisfed.org/series/CPIAUCSL.
- Fifth column (PPI):
The log-difference of the producer price index, https://fred.stlouisfed.org/series/PPIACO.
- Sixth column (RATE):
The Federal funds rate from 1954Q3 to 2008Q2 and after that the Wu and Xia (2016) shadow rate, https://fred.stlouisfed.org/series/FEDFUNDS, https://www.atlantafed.org/cqer/research/wu-xia-shadow-federal-funds-rate.
Source
The Federal Reserve Bank of St. Louis database and the Federal Reserve Bank of Atlanta's website
References
K. Gavriilidis, 2021. Measuring climate policy uncertainty. https://www.ssrn.com/abstract=3847388.
Federal Reserve Bank of Chicago. 2023. Monthly GDP Growth Rate Data. https://www.chicagofed.org/publications/bbki/index.
Virolainen S. 2025. Identification by non-Gaussianity in structural smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.
Wu J. and Xia F. 2016. Measuring the macroeconomic impact of monetary policy at the zero lower bound. Journal of Money, Credit and Banking, 48(2-3): 253-291.
U.S. real GDP, GDP implicit price deflator, and interest rate data
Description
A quarterly U.S. data covering the period from 1954Q3 to 2021Q4 (270 observations) and consisting three variables: cyclical component of the log of real GDP, the log-difference of GDP implicit price deflator, and an interest rate variable. The interest rate variable is the effective federal funds rate from 1954Q3 to 2008Q2 and after that the Wu and Xia (2016) shadow rate, which is not constrained by the zero lower bound and also quantifies unconventional monetary policy measures. The log-differences of the GDP deflator and producer price index are multiplied by hundred.
The cyclical component of the log of real GDP was obtained by applying a one-sided Hodrick-Prescott (HP) filter with the standard smoothing parameter lambda=1600. The one-sided filter was obtained from the two-sided HP filter by applying the filter up to horizon t, taking the last observation, and repeating this procedure for the full sample t=1,...,T. In order to allow the series to start from any phase of the cycle, we applied the one-sided filter to the full available sample from 1947Q1 to 2021Q1 before extracting our sample period from it. We computed the two-sided HP filters with the R package lpirfs (Adämmer, 2021)
Usage
usamone
Format
A numeric matrix of class 'ts'
with 270 rows and 4 columns with one time series in each column:
- First column (GDP):
The cyclical component of the log of real GDP, https://fred.stlouisfed.org/series/GDPC1.
- Second column (GDPDEF):
The log-difference of GDP implicit price deflator, https://fred.stlouisfed.org/series/GDPDEF.
- Third column (RATE):
The Federal funds rate from 1954Q3 to 2008Q2 and after that the Wu and Xia (2016) shadow rate, https://fred.stlouisfed.org/series/FEDFUNDS, https://www.atlantafed.org/cqer/research/wu-xia-shadow-federal-funds-rate.
Source
The Federal Reserve Bank of St. Louis database and the Federal Reserve Bank of Atlanta's website
References
Adämmer P. 2021. lprfs: Local Projections Impulse Response Functions. R package version: 0.2.0, https://CRAN.R-project.org/package=lpirfs.
Wu J. and Xia F. 2016. Measuring the macroeconomic impact of monetary policy at the zero lower bound. Journal of Money, Credit and Banking, 48(2-3): 253-291.
Vectorization operator
Description
vec
stacks columns of the given matrix to form a vector.
Usage
vec(A)
Arguments
A |
a size |
Value
a vector of size (d^2x1)
.
Parsimonious vectorization operator for symmetric matrices
Description
vech
stacks columns of the given matrix from
the principal diagonal downwards (including elements on the diagonal) to form a vector.
Usage
vech(A)
Arguments
A |
a size |
Value
a vector of size (d(d+1)/2x1)
.
Warn about near-unit-roots in some regimes
Description
warn_eigens
warns if the model contains near-unit-roots in some regimes
Usage
warn_eigens(stvar, tol = 0.002, allow_unstab = FALSE)
Arguments
stvar |
object of class |
tol |
if eigenvalue is closer than |
allow_unstab |
If |
Details
Warns if, for some regime, some moduli of "bold A" eigenvalues are larger than 1 - tol
or
some eigenvalue of the error term covariance matrix is smaller than tol
.
Value
Doesn't return anything.