MatthieuStigler / tsDyn

tsDyn
tsdyn.googlecode.com
GNU General Public License v2.0
34 stars 20 forks source link

Setar command: specification of levels and first differences #40

Open LukasWiechers opened 2 years ago

LukasWiechers commented 2 years ago

Hi Matthieu!

Thanks for your reply. Here is once again my question with some adjustments, subsequently the example in R.

I have an understanding problem concerning the setar command in your tsDyn package for R. It basically centers around the question how to define the time series X in combination with the argument type in setar. If i take differences of X beforehand and use type="level", the result is different compared to using non-differenced X in combination with type="diff". Differently spoken, setar(differences of X, type="level") [model 1 in the following code] is not equal to setar(X, type="diff") [model 2].

If I understand the comments in "Nonlinear autoregressive time series models in R using tsdyn version 0.7" correctly, the reason should be a differently defined threshold variable Z in the two cases. Am I correct that Z is only affected by the model argument? That is, first differences of Z are only due to model="MTAR" and not due to type="diff"?

I found this to be reasonable since I realized that setar(differences of X, type="level") [model 1] is equal to setar(X, type="diff", model="MTAR") [model 3]. Then, in both cases, X and Z should be in first differences. Though, setar(X, type="diff")[model 2] should take X in differences but not Z (i.e. Z is in levels).

Is my understanding correct?

Many thanks! Lukas

Here my example in R; the dataset used is in the attachment. EP_LLR_residuals.ub.txt

library(tsDyn)

### input of residual series of real US-GDP, detrended using local linear regression ###    

Y1=read.table("EP_LLR_residuals.ub.txt", header=TRUE)   

EP_LLR_residuals.ub=Y1[,1]

### first differences of the original residual series ###

EP_LLR_residuals.ub_diff=diff(EP_LLR_residuals.ub)  

### fitting SETAR models, results differ ###

SETAR_EP_LLR_residuals.ub_1 <- setar(EP_LLR_residuals.ub_diff, mL=1, mH=1, m=1, type="level")           ### use data in first differences, type="level" ###
SETAR_EP_LLR_residuals.ub_2 <- setar(EP_LLR_residuals.ub, mL=1, mH=1, m=1, type="diff")             ### use level data, type="diff" ###

#> SETAR_EP_LLR_residuals.ub_1$coefficients
#     const.L       phiL.1      const.H       phiH.1           th 
#-0.014429253 -0.668057144  0.000393548  0.157633721 -0.005668589 

#> SETAR_EP_LLR_residuals.ub_2$coefficients
#     const.L      DphiL.1      const.H      DphiH.1           th 
# 0.004790568 -0.300837628 -0.001284661  0.456027467 -0.013095617 

### fitting SETAR models, results are equal ###

SETAR_EP_LLR_residuals.ub_1 <- setar(EP_LLR_residuals.ub_diff, mL=1, mH=1, m=1, type="level")           ### as above ###
SETAR_EP_LLR_residuals.ub_3 <- setar(EP_LLR_residuals.ub, mL=1, mH=1, m=1, type="diff", model="MTAR")       ### use level data, type="diff", model="MTAR" ###       

#> SETAR_EP_LLR_residuals.ub_1$coefficients
#     const.L       phiL.1      const.H       phiH.1           th 
#-0.014429253 -0.668057144  0.000393548  0.157633721 -0.005668589 

#> SETAR_EP_LLR_residuals.ub_3$coefficients
#     const.L      DphiL.1      const.H      DphiH.1           th 
#-0.014429253 -0.668057144  0.000393548  0.157633721 -0.005668589
MatthieuStigler commented 2 years ago

reprex:

library(tsDyn)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

X <- lynx
X_d <- diff(X)  

### fitting SETAR models, results differ ###
SETAR_X_diff <- setar(X, mL=1, mH=1, m=1, type="diff")              ### use level data, type="diff" ###
SETAR_Xd_level <- setar(X_d, mL=1, mH=1, m=1, type="level")         ### use data in first differences, type="level" ###

coef(SETAR_X_diff)
#>       const.L       DphiL.1       const.H       DphiH.1            th 
#>   283.1913690     0.5475225 -1459.3260261     0.5254615  3091.0000000
coef(SETAR_Xd_level)
#>      const.L       phiL.1      const.H       phiH.1           th 
#>   99.4300045    0.5825838 1970.6392670   -0.8601700  810.0000000

### fitting SETAR midels, results are equal ###
SETAR_Xd_level <- setar(X_d, mL=1, mH=1, m=1, type="level")         ### as above ###
SETAR_X_diff_MTAR <- setar(X, mL=1, mH=1, m=1, type="diff", model="MTAR")       ### use level data, type="diff", model="MTAR" ###       

all.equal(coef(SETAR_Xd_level),
          coef(SETAR_X_diff_MTAR), check.attributes = FALSE)
#> [1] TRUE

Created on 2022-04-07 by the reprex package (v2.0.1)

MatthieuStigler commented 2 years ago

Hi Lukas!

Sorry for the slow response. And yes, your interpretation is correct. I realize the help file is not very... helpful. What do you think about following amendments?

\item{model}{Whether the threshold variable is taken in levels (TAR) or differences (MTAR)} \item{type}{Whether the variable is taken is level, difference or a mix (diff y= y-1, diff lags) as in the ADF test. Note this does not affect le transition variable, see argument model}

LukasWiechers commented 2 years ago

Hi Matthieu!

I think your amendments are clear. The reference manual for version 11.0.2 currently states that the model argument is not implemented at all. However, as for myself, I think it is the best to always use the data in levels and then set both model and type as desired. Instead, taking already differenced data and omitting one of those arguments may be misleading. Many thanks for your help!

Best regards, Lukas