Title: | Bayesian Estimation of Multivariate Threshold Autoregressive Models |
---|---|
Description: | Estimation, inference and forecasting using the Bayesian approach for multivariate threshold autoregressive (TAR) models in which the distribution used to describe the noise process belongs to the class of Gaussian variance mixtures. |
Authors: | Luis Hernando Vanegas [aut, cre], Sergio Alejandro Calderón [aut], Luz Marina Rondón [aut] |
Maintainer: | Luis Hernando Vanegas <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 0.1.2 |
Built: | 2025-02-18 03:39:58 UTC |
Source: | https://github.com/cran/mtarm |
This function converts the chains obtained from the Bayesian estimation of a multivariate TAR model to a mcmc
object to be analyzed with the coda package.
convert(object, type = c("location", "scale", "extra"), regime = 1)
convert(object, type = c("location", "scale", "extra"), regime = 1)
object |
an object of the class mtar. |
type |
an (optional) character string that allows the user to specify the parameter that corresponds to the
chains to convert. The available options are: "location", "scale" and "extra". As default, |
regime |
an (optional) integer value that allows the user to specify the regime that corresponds to the chains to plot.
As default, |
a mcmc
-type object.
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1 <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Slash", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) location.chains.1 <- convert(fit1,type="location",regime=2) summary(location.chains.1) plot(location.chains.1) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2 <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Laplace", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) location.chains.2 <- convert(fit2,type="location",regime=3) summary(location.chains.2) plot(location.chains.2)
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1 <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Slash", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) location.chains.1 <- convert(fit1,type="location",regime=2) summary(location.chains.1) plot(location.chains.1) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2 <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Laplace", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) location.chains.2 <- convert(fit2,type="location",regime=3) summary(location.chains.2) plot(location.chains.2)
This function computes the Deviance information criterion (DIC) for objects of class mtar
.
DIC(..., verbose = TRUE, digits = max(3, getOption("digits") - 2))
DIC(..., verbose = TRUE, digits = max(3, getOption("digits") - 2))
... |
one or several objects of the class mtar. |
verbose |
an (optional) logical switch indicating if should the report of results be printed. As default, |
digits |
an (optional) integer indicating the number of digits to print. As default, |
A data.frame
with the values of the DIC for each mtar object in the input.
Spiegelhalter D.J., Best N.G., Carlin B.P. and Van Der Linde A. (2002) Bayesian Measures of Model Complexity and Fit. Journal of the Royal Statistical Society Series B (Statistical Methodology), 64(4), 583–639.
Spiegelhalter D.J., Best N.G., Carlin B.P. and Van der Linde A. (2014). The deviance information criterion: 12 years on. Journal of the Royal Statistical Society Series B (Statistical Methodology), 76(3), 485–493.
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1a <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Gaussian", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) fit1b <- update(fit1a,dist="Slash") fit1c <- update(fit1a,dist="Student-t") DIC(fit1a,fit1b,fit1c) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2a <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Gaussian", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) fit2b <- update(fit2a,dist="Slash") fit2c <- update(fit2a,dist="Student-t") DIC(fit2a,fit2b,fit2c)
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1a <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Gaussian", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) fit1b <- update(fit1a,dist="Slash") fit1c <- update(fit1a,dist="Student-t") DIC(fit1a,fit1b,fit1c) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2a <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Gaussian", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) fit2b <- update(fit2a,dist="Slash") fit2c <- update(fit2a,dist="Student-t") DIC(fit2a,fit2b,fit2c)
This function computes forecasting from a fitted multivariate TAR model.
forecasting(object, data, credible = 0.95, row.names)
forecasting(object, data, credible = 0.95, row.names)
object |
an object of the class mtar. |
data |
an (optional) data frame, list or environment (or object coercible by
as.data.frame to a data frame) containing the future values of the threshold
series as well as the exogenous series in the model.
If not found in data, the variables are taken from |
credible |
an (optional) value for the level of the credible intervals. As default, |
row.names |
an (optional) vector that allows the user to name the time point to
which each row in the data set |
a list with the following component
ypred |
a matrix with the results of the forecasting, |
summary |
a matrix with the mean, standard deviation, and the HDP credible intervals of the forecasting, |
Nieto, F.H. (2005) Modeling Bivariate Threshold Autoregressive Processes in the Presence of Missing Data. Communications in Statistics - Theory and Methods, 34, 905-930.
Romero, L.V. and Calderon, S.A. (2021) Bayesian estimation of a multivariate TAR model when the noise process follows a Student-t distribution. Communications in Statistics - Theory and Methods, 50, 2508-2530.
Calderon, S.A. and Nieto, F.H. (2017) Bayesian analysis of multivariate threshold autoregressive models with missing data. Communications in Statistics - Theory and Methods, 46, 296-318.
Karlsson, S. (2013) Chapter 15-Forecasting with Bayesian Vector Autoregression. In Elliott, G. and Timmermann, A. Handbook of Economic Forecasting, Volume 2, 791–89, Elsevier.
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1 <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Slash", data=subset(returns,Date < "2016-03-20"), ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) out1 <- forecasting(fit1,data=subset(returns,Date >= "2016-03-20"),row.names=Date) out1$summary ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2 <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Laplace", data=subset(riverflows,Date < "2009-04-09"), ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) out2 <- forecasting(fit2,data=subset(riverflows,Date >= "2009-04-09"),row.names=Date) out2$summary
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1 <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Slash", data=subset(returns,Date < "2016-03-20"), ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) out1 <- forecasting(fit1,data=subset(returns,Date >= "2016-03-20"),row.names=Date) out1$summary ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2 <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Laplace", data=subset(riverflows,Date < "2009-04-09"), ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) out2 <- forecasting(fit2,data=subset(riverflows,Date >= "2009-04-09"),row.names=Date) out2$summary
This function uses Gibbs sampling to generate a sample from the posterior
distribution of the parameters of a multivariate TAR model when the noise
process follows Gaussian, Student-, Slash, Symmetric Hyperbolic,
Contaminated normal, or Laplace distribution.
mtar( formula, data, subset, Intercept = TRUE, ars, row.names, dist = "Gaussian", prior = list(), n.sim = 500, n.burnin = 100, n.thin = 1, log = FALSE, ... )
mtar( formula, data, subset, Intercept = TRUE, ars, row.names, dist = "Gaussian", prior = list(), n.sim = 500, n.burnin = 100, n.thin = 1, log = FALSE, ... )
formula |
a three-part expression of type |
data |
an (optional) data frame, list or environment (or object coercible by
as.data.frame to a data frame) containing the variables in the model.
If not found in data, the variables are taken from |
subset |
an (optional) vector specifying a subset of observations to be used in the fitting process. |
Intercept |
an (optional) logical variable. If |
ars |
a list composed of three objects, namely: |
row.names |
an (optional) vector that allows the user to name the time point to which each row in the data set corresponds. |
dist |
an (optional) character string that 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- |
prior |
an (optional) list that allows the user to specify the values of the hyperparameters, that is, allows to specify the values of the parameters of the prior distributions. |
n.sim |
an (optional) positive integer specifying the required number of iterations
for the simulation after the burn-in period. As default, |
n.burnin |
an (optional) positive integer specifying the required number of burn-in
iterations for the simulation. As default, |
n.thin |
an (optional) positive integer specifying the required thinning interval
for the simulation. As default, |
log |
an (optional) logical variable. If |
... |
further arguments passed to or from other methods. |
an object of class mtar in which the main results of the model fitted to the data are stored, i.e., a list with components including
chains |
list with several arrays, which store the values of each model parameter in each iteration of the simulation, |
n.sim |
number of iterations of the simulation after the burn-in period, |
n.burnin |
number of burn-in iterations in the simulation, |
n.thin |
thinning interval in the simulation, |
regim |
number of regimes, |
ars |
list composed of three objects, namely: p , q and d ,
each of which corresponds to a vector of non-negative integers with as
many elements as there are regimes in the TAR model, |
dist |
name of the multivariate distribution used to describe the behavior of the noise process, |
threshold.series |
vector with the values of the threshold series, |
response.series |
matrix with the values of the output series, |
covariable.series |
matrix with the values of the exogenous series, |
Intercept |
If TRUE , then the model included an intercept term, |
formula |
the formula, |
call |
the original function call. |
Nieto, F.H. (2005) Modeling Bivariate Threshold Autoregressive Processes in the Presence of Missing Data. Communications in Statistics - Theory and Methods, 34, 905-930.
Romero, L.V. and Calderon, S.A. (2021) Bayesian estimation of a multivariate TAR model when the noise process follows a Student-t distribution. Communications in Statistics - Theory and Methods, 50, 2508-2530.
Calderon, S.A. and Nieto, F.H. (2017) Bayesian analysis of multivariate threshold autoregressive models with missing data. Communications in Statistics - Theory and Methods, 46, 296-318.
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1 <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Slash", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) summary(fit1) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2 <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Laplace", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) summary(fit2)
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1 <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Slash", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) summary(fit1) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2 <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Laplace", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) summary(fit2)
These data correspond to the returns of closing prices of the Colcap, Bovespa, and S&P 500 indexes from 2010-02-01 to 2016-03-31 (1505 time points). Colcap is a leading indicator of the price dynamics of the 20 most liquid shares on the Colombian Stock Market. Bovespa is the Brazilian stock market index, the world's thirteenth largest and most important stock exchange, and the first in Latin America. Finally, the Standard & Poor's 500 (S&P 500) index is a stock index based on the 500 largest companies in the United States.
data(returns)
data(returns)
A data frame with 1505 rows and 4 variables:
a vector indicating the dates of the measurements.
a numeric vector indicating the returns of COLCAP.
a numeric vector indicating the returns of SP500.
a numeric vector indicating the returns of BOVESPA.
Romero, L.V. and Calderon, S.A. (2021) Bayesian estimation of a multivariate TAR model when the noise process follows a Student-t distribution. Communications in Statistics - Theory and Methods, 50, 2508-2530.
data(returns) dev.new() plot(ts(as.matrix(returns[,-1])), main="Returns")
data(returns) dev.new() plot(ts(as.matrix(returns[,-1])), main="Returns")
The data represent daily rainfall (in mm) and two river
flows (in /s) in southern Colombia. A meteorological station located
with an altitude of 2400 meters was used to measure rainfall. In the
first case, the El Trebol hydrological station was used to measure the
flow in the Bedon river at an altitude of 1720 meters. In the second
case, the Villalosada hydrological station measured the flow in the
La Plata river at an altitude of 1300 meters. Geographically, the
stations are located near the equator. The last characteristic allows
for control over hydrological and meteorological factors that might
distort a dynamic relationship. January 1, 2006, to April 14, 2009,
is the sample period.
data(riverflows)
data(riverflows)
A data frame with 1200 rows and 4 variables:
a vector indicating the dates of the measurements.
a numeric vector indicating the Bedon river flow.
a numeric vector indicating the La Plata river flow.
a numeric vector indicating the rainfall.
Calderon, S.A. and Nieto, F.H. (2017) Bayesian analysis of multivariate threshold autoregressive models with missing data. Communications in Statistics - Theory and Methods, 46, 296-318.
data(riverflows) dev.new() plot(ts(as.matrix(riverflows[,-1])), main="Rainfall and river flows")
data(riverflows) dev.new() plot(ts(as.matrix(riverflows[,-1])), main="Rainfall and river flows")
This function simulates multivariate time series according to a user-specified TAR model.
simtar( n, k = 2, ars = list(p = 1), Intercept = TRUE, parms, delay = 0, thresholds = 0, t.series, ex.series, dist = "gaussian", extra )
simtar( n, k = 2, ars = list(p = 1), Intercept = TRUE, parms, delay = 0, thresholds = 0, t.series, ex.series, dist = "gaussian", extra )
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: |
Intercept |
an (optional) logical variable. If |
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 |
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- |
extra |
a value indicating the value of the extra parameter of the noise process distribution, if any. |
a data.frame
containing the output series, threshold series (if any), and multivariate exogenous series (if any).
###### 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(i in 1:length(ars$p)){ np <- Intercept + ars$p[i]*k parms[[i]] <- list() parms[[i]]$location <- c(ifelse(runif(np*k)<=0.5,1,-1)*rbeta(np*k,shape1=4,shape2=16)) parms[[i]]$location <- matrix(parms[[i]]$location,np,k) parms[[i]]$scale <- rgamma(k,shape=1,scale=1)*diag(k) } thresholds <- quantile(Z,probs=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) ###### Simulation of a trivariate VAR model n <- 2000 k <- 3 ars <- list(p=2) Intercept <- TRUE parms <- list() for(i in 1:length(ars$p)){ np <- Intercept + ars$p[i]*k parms[[i]] <- list() parms[[i]]$location <- c(ifelse(runif(np*k)<=0.5,1,-1)*rbeta(np*k,shape1=4,shape2=16)) parms[[i]]$location <- matrix(parms[[i]]$location,np,k) parms[[i]]$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)
###### 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(i in 1:length(ars$p)){ np <- Intercept + ars$p[i]*k parms[[i]] <- list() parms[[i]]$location <- c(ifelse(runif(np*k)<=0.5,1,-1)*rbeta(np*k,shape1=4,shape2=16)) parms[[i]]$location <- matrix(parms[[i]]$location,np,k) parms[[i]]$scale <- rgamma(k,shape=1,scale=1)*diag(k) } thresholds <- quantile(Z,probs=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) ###### Simulation of a trivariate VAR model n <- 2000 k <- 3 ars <- list(p=2) Intercept <- TRUE parms <- list() for(i in 1:length(ars$p)){ np <- Intercept + ars$p[i]*k parms[[i]] <- list() parms[[i]]$location <- c(ifelse(runif(np*k)<=0.5,1,-1)*rbeta(np*k,shape1=4,shape2=16)) parms[[i]]$location <- matrix(parms[[i]]$location,np,k) parms[[i]]$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)
This function computes the Watanabe-Akaike or Widely Available Information criterion (WAIC) for objects of class mtar
.
WAIC(..., verbose = TRUE, digits = max(3, getOption("digits") - 2))
WAIC(..., verbose = TRUE, digits = max(3, getOption("digits") - 2))
... |
one or several objects of the class mtar. |
verbose |
an (optional) logical switch indicating if should the report of results be printed. As default, |
digits |
an (optional) integer indicating the number of digits to print. As default, |
A data.frame
with the values of the WAIC for each mtar object in the input.
Watanabe S. (2010). Asymptotic Equivalence of Bayes Cross Validation and Widely Applicable Information Criterion in Singular Learning Theory. The Journal of Machine Learning Research, 11, 3571–3594.
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1a <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Gaussian", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) fit1b <- update(fit1a,dist="Slash") fit1c <- update(fit1a,dist="Student-t") WAIC(fit1a,fit1b,fit1c) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2a <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Gaussian", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) fit2b <- update(fit2a,dist="Slash") fit2c <- update(fit2a,dist="Student-t") WAIC(fit2a,fit2b,fit2c)
###### Example 1: Returns of the closing prices of three financial indexes data(returns) fit1a <- mtar(~ COLCAP + BOVESPA | SP500, row.names=Date, dist="Gaussian", data=returns, ars=list(p=c(1,1,2)), n.burnin=100, n.sim=3000) fit1b <- update(fit1a,dist="Slash") fit1c <- update(fit1a,dist="Student-t") WAIC(fit1a,fit1b,fit1c) ###### Example 2: Rainfall and two river flows in Colombia data(riverflows) fit2a <- mtar(~ Bedon + LaPlata | Rainfall, row.names=Date, dist="Gaussian", data=riverflows, ars=list(p=c(5,5,5)), n.burnin=100, n.sim=3000) fit2b <- update(fit2a,dist="Slash") fit2c <- update(fit2a,dist="Student-t") WAIC(fit2a,fit2b,fit2c)