simtar: Simulation of multivariate time series from a TAR model

View source: R/simulation.R

simtarR Documentation

Simulation of multivariate time series from a TAR model

Description

This function simulates multivariate time series generated by a user-specified Threshold Autoregressive (TAR) model.

Usage

simtar(
  n,
  k = 2,
  ars = ars(),
  Intercept = TRUE,
  trend = c("none", "linear", "quadratic"),
  nseason = NULL,
  parms,
  delay = 0,
  thresholds = NULL,
  t.series = NULL,
  ex.series = NULL,
  dist = c("Gaussian", "Student-t", "Hyperbolic", "Laplace", "Slash",
    "Contaminated normal", "Skew-Student-t", "Skew-normal"),
  skewness = NULL,
  extra = NULL,
  setar = NULL,
  Verbose = TRUE
)

Arguments

n

A positive integer specifying the length of the simulated output series.

k

A positive integer specifying the dimension of the multivariate output series.

ars

A list defining the TAR model structure, composed of four elements: the number of regimes (nregim), the autoregressive order (p), and the maximum lags of the exogenous (q) and threshold (d) series within each regime. This object can be validated using the ars() function.

Intercept

An optional logical indicating whether an intercept term is included in each regime.

trend

An optional character string specifying the degree of deterministic time trend to be included in each regime. Available options are a linear trend ("linear"), a quadratic trend ("quadratic"), or no trend ("none"). By default, trend is set to "none".

nseason

An optional integer, greater than or equal to 2, specifying the number of seasonal periods. When provided, nseason - 1 seasonal dummy variables are added to the regressors within each regime. By default, nseason is set to NULL, thereby indicating that the TAR model has no seasonal effects.

parms

A list with one sublist per regime. Each sublist contains two matrices: the first matrix corresponds to the location parameters, and the second matrix corresponds to the scale parameters of the model.

delay

An optional non-negative integer specifying the delay parameter of the threshold series. By default, delay is set to 0.

thresholds

A numeric vector of length nregim-1 containing the threshold values, sorted in ascending order.

t.series

A matrix containing the values of the threshold series.

ex.series

A matrix containing the values of the multivariate exogenous series.

dist

An optional character string specifying the multivariate distribution chosen to model the noise process. Supported options include Gaussian ("Gaussian"), Student-t ("Student-t"), Slash ("Slash"), Symmetric Hyperbolic ("Hyperbolic"), Laplace ("Laplace"), and Contaminated Normal ("Contaminated normal"). By default, dist is set to "Gaussian".

skewness

An optional numeric vector specifying the skewness parameters of the noise distribution, when applicable.

extra

An optional value specifying the extra parameter of the noise distribution, when required.

setar

An optional positive integer indicating which component of the output series is used as the threshold variable. By default, setar is set to NULL, indicating that the model is not of SETAR type.

Verbose

An optional logical indicating whether a description of the simulated TAR model should be printed. By default, Verbose is set to TRUE.

Value

A data.frame containing the simulated multivariate output series, and, if specified, the threshold series and multivariate exogenous series.

References

Vanegas, L.H. and Calderón, S.A. and Rondón, L.M. (2025) Bayesian estimation of a multivariate tar model when the noise process distribution belongs to the class of gaussian variance mixtures. International Journal of Forecasting.

Examples


###### Simulation of a trivariate TAR model with two regimes
n <- 2000
k <- 3
myars <- ars(nregim=2,p=c(1,2))
Z <- as.matrix(arima.sim(n=n+max(myars$p),list(ar=c(0.5))))
probs <- sort((0.6 + runif(myars$nregim-1)*0.8)*c(1:(myars$nregim-1))/myars$nregim)
dist <- "Student-t"; extra <- 6
parms <- list()
for(j in 1:myars$nregim){
    np <- 1 + myars$p[j]*k
    parms[[j]] <- list()
    parms[[j]]$location <- c(ifelse(runif(np*k)<=0.5,1,-1)*rbeta(np*k,shape1=4,shape2=16))
    parms[[j]]$location <- matrix(parms[[j]]$location,np,k)
    parms[[j]]$scale <- rgamma(k,shape=1,scale=1)*diag(k)
}
thresholds <- quantile(Z,probs=probs)
out1 <- simtar(n=n, k=k, ars=myars, parms=parms, thresholds=thresholds,
               t.series=Z, dist=dist, extra=extra)
str(out1)

fit1 <- mtar(~ Y1 + Y2 + Y3 | Z, data=out1, ars=myars, dist=dist,
             n.burn=2000, n.sim=3000, n.thin=2)
summary(fit1)

###### Simulation of a trivariate VAR model
n <- 2000
k <- 3
myars <- ars(nregim=1,p=2)
dist <- "Slash"; extra <- 2
parms <- list()
for(j in 1:myars$nregim){
    np <- 1 + myars$p[j]*k
    parms[[j]] <- list()
    parms[[j]]$location <- c(ifelse(runif(np*k)<=0.5,1,-1)*rbeta(np*k,shape1=4,shape2=16))
    parms[[j]]$location <- matrix(parms[[j]]$location,np,k)
    parms[[j]]$scale <- rgamma(k,shape=1,scale=1)*diag(k)
}
out2 <- simtar(n=n, k=k, ars=myars, parms=parms, dist=dist, extra=extra)
str(out2)

fit2 <- mtar(~ Y1 + Y2 + Y3, data=out2, ars=myars, dist=dist,
             n.burn=2000, n.sim=3000, n.thin=2)
summary(fit2)

n <- 5000
k <- 3
myars <- ars(nregim=2,p=c(1,2))
dist <- "Laplace"
parms <- list()
for(j in 1:myars$nregim){
    np <- 1 + myars$p[j]*k
    parms[[j]] <- list()
    parms[[j]]$location <- c(ifelse(runif(np*k)<=0.5,1,-1)*rbeta(np*k,shape1=4,shape2=16))
    parms[[j]]$location <- matrix(parms[[j]]$location,np,k)
    parms[[j]]$scale <- rgamma(k,shape=1,scale=1)*diag(k)
}
out3 <- simtar(n=n, k=k, ars=myars, parms=parms, delay=2,
               thresholds=-1, dist=dist, setar=2)
str(out3)

fit3 <- mtar(~ Y1 + Y2 + Y3, data=out3, ars=myars, dist=dist,
             n.burn=2000, n.sim=3000, n.thin=2, setar=2)
summary(fit3)




mtarm documentation built on Jan. 12, 2026, 1:07 a.m.

Related to simtar in mtarm...