Estimating Threshold of Time Series Using R

Published by chengjun on March 20th, 2012

Please note that I am NOT an expert in time series analysis. Therefore, I am not the ideal person to answer the technical questions on this topic. Please consider (1) raising your question on stackoverflow, (2) sending emails to the developer of related R packages, (3) joining related email groups, etc.

The method of estimating Threshold of Time Series Data has been developed by R. This post shows how to use the method by adopting two packages. First, I would like to highlight Bruce Hansen’s work in this field.

Bruce E. Hansen


Programs — Threshold Models


“Inference when a nuisance parameter is not identified under the null hypothesis.” Econometrica, (1996). [Download].

“Inference in TAR models.” Studies in Nonlinear Dynamics and Econometrics, (1997). [Download].

“Threshold effects in non-dynamic panels: Estimation, testing and inference.” Journal of Econometrics, (1999). [Download].

“Testing for Linearity.” Journal of Economic Surveys, (1999). [Download].

“Sample splitting and threshold estimation.” Econometrica, (2000). [Download].

“Threshold Autoregression with a Unit Root.” Econometrica (2001), with Mehmet Caner. [Download].

“How responsive are private transfers to income? Evidence from a laissez-faire economy.”
with Donald Cox and Emmanuel Jimenez, Journal of Public Economics, (2004), 88, 2193-2219. [Download].

“Testing for two-regime threshold cointegration in vector error correction models,” with Byeongseon Seo, Journal of Econometrics (2002). [Download].

“Instrumental Variable Estimation of a Threshold Model”, with Mehmet Caner, Econometric Theory, (2004), 20, 813-843. [Download].

# Chengjun WANG
# @anu, 20120320
#~~~~~~~~~~~~~~~~urca~~~~~~~~~~~~~~~~~~~~~~~~~#
# The first step is Unit root and cointegration Analysis (urca)
# install.packages("urca")
# load the package
library(urca)
# see the data which is used as an example
data(denmark)
data(finland)
#~~~~~~~~~~~~~~~threshold model using tsDyn~~~~~~~~~~~~~~~~~~~~~~~#
# install.packages("tsDyn")
# load the package of tsDyn
library(tsDyn)

# models in this package
availableModels()
 [1] "linear"  "nnetTs"  "setar"   "lstar"   "star"    "aar"     "lineVar"
 [8] "VECM"    "TVAR"    "TVECM"

#fit an AAR model:
mod #Summary data informations:
summary(mod)
#Diagnostic plots:
plot(mod)

# STAR model fitting with automatic selection of the number
# of regimes based on LM tests.

mod.star mod.star

addRegime(mod.star)

# Estimate a multivariate Threshold VAR
?TVAR  # ask r to introduce about TVAR

data(zeroyld)

data
TVAR(data, lag=2, nthresh=2, thDelay=1, trim=0.1, mTh=1, plot=TRUE)
TVAR.LRtest(data, lag=2, mTh=1,thDelay=1:2, nboot=3, plot=FALSE, trim=0.1, test="1vs")

# The one threshold (two regimes) gives a value of 10.698 for the
# threshold and 1 for the delay. Conditional on this values, the search
# for a second threshold (three regimes) gives 8.129. Starting from this
# values, a full grid search finds the same values and confims the first
# step estimation.

##simulate VAR as in Enders 2004, p 268
B1var1ts.plot(var1, type="l", col=c(1,2))

B2varcovvar2ts.plot(var2, type="l", col=c(1,2))

##Simulation of a TVAR with 1 threshold
Bsim
#estimate the new serie
TVAR(sim, lag=1, dummyToBothRegimes=TRUE)

##Bootstrap a TVAR with two threshold (three regimes)
data(zeroyld)
serieTVAR.sim(data=serie,nthresh=2, type="boot",mTh=1, Thresh=c(7,9))

##Check the bootstrap
cbind(TVAR.sim(data=serie,nthresh=2, type="check",mTh=1, Thresh=c(7,9)),serie)

# Estimate a Threshold Vector Error Correction model (VECM)
# Hansen, B. and Seo, B. (2002), Testing for two-regime threshold cointegration in vector error-correction models, Journal of Econometrics, 110, pages 293 - 318
data(zeroyld)
data
##Estimate a TVECM (we use here minimal grid, it should be usually much bigger!)

tv
print(tv)
summary(tv)

#Obtain diverse infos:
AIC(tv)
BIC(tv)

res.tv
#export the equations as Latex:
toLatex(tv)
    分享到:


3 Responses

  1. Joaquim Ferreira says:

    Dear Chengjun Wang,

    I am a Phd Student as well. This way, i am sending an email to you whether you coul help with the codes/routines of a TVAR/TVEC model.I would appreciate vey much if you could provide me the codes.

    yours sincerely

    Joaquim Ferreira

  2. Achille says:

    Hi dear Chengjun Wang,
    I’m Achille and i’m working on population modeling. I need your help on conducting TVECM impulse response function. Please can you help me by providing codes and routines on irf. I’ve already simulated the TVECM for population and i need to show also their irf on my work

    Thank you very much for your help.

  3. An says:

    Dear Mr Chengjun Wang,
    My name is An. I read the code in expand link but I have some question . I see you wrote that “# Estimate a Threshold Vector Error Correction model (VECM)
    # Hansen, B. and Seo, B. (2002), Testing for two-regime threshold cointegration in vector error-correction models, Journal of Econometrics, 110, pages 293 – 318
    data(zeroyld)
    data
    ##Estimate a TVECM (we use here minimal grid, it should be usually much bigger!)”
    However I don’t see the command code to estimate TVECM under this sentence. Could you explain it for me? Could you give me the command code to run TVECM in 2 regime ?
    Thank you so much for your attention
    I’m very glad if you answer my question.

    Thanh An


Leave a Reply

Your email address will not be published. Required fields are marked *