simulate.stvar {sstvars}R Documentation

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,
  burn_in = 1000,
  exo_weights = NULL,
  drop = TRUE,
  girf_pars = NULL
)

Arguments

object

an object of class 'stvar'.

nsim

number of observations to be simulated.

seed

set seed for the random number generator?

...

currently not in use.

init_values

a size (p\times d) matrix specifying the initial values, where d is the number of time series in the system. The last row will be used as initial values for the first lag, the second last row for second lag etc. If not specified, initial values will be drawn from the regime specified in init_regimes (for Gaussian models only).

init_regime

an integer in 1,...,M specifying the regime from which the initial values should be generated from. The initial values will be generated from the stationary distribution of the specific regime. Due to the lack of knowledge of the stationary distribution, models with other than Gaussian conditional distribution uses a simulation procedure with a burn-in period. See the details section.

ntimes

how many sets of simulations should be performed?

burn_in

Burn-in period for simulating initial values from a regime when cond_dist!="Gaussian". See the details section.

exo_weights

if weight_function="exogenous", provide a size (nsim \times M) matrix of exogenous transition weights for the regimes: [t, m] for a time t and regime m weight. Ignored if weight_function!="exogenous".

drop

if TRUE (default) then the components of the returned list are coerced to lower dimension if ntimes==1, i.e., $sample and $transition_weights will be matrices, and $component will be vector.

girf_pars

This argument is used internally in the estimation of generalized impulse response functions (see ?GIRF). You should ignore it (specifying something else than null to it will change how the function behaves).

Details

The stationary distribution of each regime is not known when cond_dist!="Gaussian". Therefore, when using init_regime to simulate the initial values from a given regime, we employ the following simulation procedure to obtain the initial values. 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 (nsim\times d) matrix containing the simulated time series.

transition weights:

a size (nsim\times M) matrix containing the transition weights corresponding to the simulated sample.

Otherwise, returns a list with the following entries:

$sample

a size (nsim\times d\timesntimes) array containing the samples: the dimension [t, , ] is the time index, the dimension [, d, ] indicates the marginal time series, and the dimension [, , i] indicates the i:th set of simulations.

$transition_weights

a size (nsim\times M \timesntimes) array containing the transition weights corresponding to the sample: the dimension [t, , ] is the time index, the dimension [, m, ] indicates the regime, and the dimension [, , i] indicates the i:th set of simulations.

References

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

[Package sstvars version 1.0.1 Index]