simtar: Simulation of multivariate time series according to a TAR...

View source: R/mtar.R

simtarR Documentation

Simulation of multivariate time series according to a TAR model

Description

This function simulates multivariate time series according to a user-specified TAR model.

Usage

simtar(
  n,
  k = 2,
  ars = list(p = 1),
  Intercept = TRUE,
  parms,
  delay = 0,
  thresholds = 0,
  t.series,
  ex.series,
  dist = "Gaussian",
  delta = NULL,
  extra,
  setar = NULL
)

Arguments

n

a positive integer value indicating the length of the desired output series.

k

a positive integer value indicating the dimension of the desired output series.

ars

a list composed of three objects, namely: p, q and d, each of which corresponds to a vector of l non-negative integers, where l represents the number of regimes in the TAR model.

Intercept

an (optional) logical variable. If TRUE, then the model includes an intercept.

parms

a list with as many sublists as regimes in the user-specified TAR model. Each sublist is composed of two matrices. The first corresponds to location parameters, while the second corresponds to scale parameters.

delay

an (optional) non-negative integer value indicating the delay in the threshold series.

thresholds

a vector with l-1 real values sorted ascendingly.

t.series

a matrix with the values of the threshold series.

ex.series

a matrix with the values of the multivariate exogenous series.

dist

an (optional) character string which allows the user to specify the multivariate distribution to be used to describe the behavior of the noise process. The available options are: 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".

delta

an (optional) vector with the values of the skewness parameters. By default,delta is set to NULL.

extra

a value indicating the value of the extra parameter of the noise process distribution, if any.

setar

an (optional) positive integer indicating the component of the output series which should be the threshold variable. By default,setar is set to NULL.

Value

a data.frame containing the output series, threshold series (if any), and multivariate exogenous series (if any).

Examples


###### Simulation of a trivariate TAR model with two regimes
n <- 2000
k <- 3
ars <- list(p=c(1,2))
Z <- as.matrix(arima.sim(n=n+max(ars$p),list(ar=c(0.5))))
Intercept <- TRUE
parms <- list()
for(j in 1:length(ars$p)){
   np <- Intercept + ars$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=(0.85 + runif(1)*0.3)*seq(1,length(ars$p)-1)/length(ars$p))
out1 <- simtar(n=n,k=k,ars=ars,Intercept=Intercept,parms=parms,
               thresholds=thresholds,t.series=Z,dist="Student-t",extra=6)
str(out1)

fit1 <- mtar(~ Y1 + Y2 + Y3 | t.series, data=out1, ars=ars, dist="Student-t",
             nsim=3000, n.burn=2000, n.thin=2)
summary(fit1)

###### Simulation of a trivariate VAR model
n <- 2000
k <- 3
ars <- list(p=2)
Intercept <- TRUE
parms <- list()
for(j in 1:length(ars$p)){
   np <- Intercept + ars$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=ars,Intercept=Intercept,parms=parms,
               dist="Slash",extra=2)
str(out2)

fit2 <- mtar(~ Y1 + Y2 + Y3, data=out2, ars=ars, dist="Slash", nsim=3000,
             n.burn=2000, n.thin=2)
summary(fit2)
toy <- data.frame(Date=rep(0,10))
f2 <- forecasting(fit2, data=toy, row.names=Date)
f2$summary
plot(f2, n=100)

n <- 5010
k <- 3
ars <- list(p=c(1,2))
Intercept <- TRUE
parms <- list()
for(j in 1:length(ars$p)){
  np <- Intercept + ars$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=ars, Intercept=Intercept, parms=parms, delay=2,
               thresholds=-1, dist="Laplace", setar=2)
str(out3)

fit3 <- mtar(~ Y1 + Y2 + Y3 | Y2, data=out3, ars=ars, dist="Laplace",
             nsim=3000,n.burn=2000, n.thin=2, prior=list(hmin=1))
summary(fit3)
toy <- data.frame(Date=rep(0,10))
f3 <- forecasting(fit3, setar=2, data=toy, row.names=Date)
f3$summary
plot(f3, n=100)


mtarm documentation built on June 8, 2025, 10:20 a.m.

Related to simtar in mtarm...