Original link:tecdat.cn/?p=5231

Original source:Tuo End number according to the tribe public number

 

For convenience, these models are often referred to simply as TAR models. These models capture behaviors that linear time series models cannot, such as periods, amplitude dependent frequencies and jumping phenomena. Tong and Lim (1980) used a threshold model to show that the model was able to detect asymmetric periodic behavior in the occurrence of sunspot data.

An example of a first-order TAR model:

σ is the noise standard deviation, YT-1 is the threshold variable, r is the threshold parameter, {et} is the sequence of IID random variables with zero mean and unit variance.

Each linear submodel is called a mechanism. The above is a model of the two mechanisms.

Consider the following simple first-order TAR model:

# I2 = -0.2 p2 = -1.8 S2 = 1 THRESH = -1 delay = 1 # Simulation data Y =sim(n=100,Phi1=c(i1, P1),Phi2=c(i2,p2), P =1,d=delay, SIGma1 = S1, THD = Thresh,sigma2=s2)$y # plot(y=y,x=1:length(y),type='o',xlab='t',ylab=expression(Y[t]) abline(thresh,0,col="red")Copy the code

The TAR model framework is a modified version of the original TAR model. It is obtained by suppressing noise terms and intercepts and setting the threshold to 0:

The stability of the frame and some regularity conditions imply the stability of the TAR. Stability can be understood as the frame is bounded for any initial value Y1.

In the [164] :

Startvals = c(-2, -1.1,-0.5, 0.8, 1.2) For (s in startvals) {ysk[1} else {ysk[I] = -1.8*ysk[i-1]} count = count + 1} # Matplot (t (x), type = "l" abline (0, 0)Copy the code

 

 

 

Chan and Tong (1985) proved that the first-order TAR model is stationary if the following conditions are met

The general two-mechanism model is written as follows:

 

In this case, stability is more complicated. However, Chan and Tong (1985) proved that if

Model to estimate

One approach, and the one discussed here, is the conditional least squares (CLS) approach.

For simplicity, in addition to assuming p1 = p2 = p and 1≤ D ≤ P, assume σ1=σ2=σ. The TAR model can then be conveniently written as

If Yt-d> r, then I (Yt-d> r) = 1, otherwise 0. CLS minimizes the sum of squares of conditional residuals:

 

In this case, the data can be divided into two parts according to whether Yt-d≤ R, and then OLS is performed to estimate the parameters of each linear submodel.

If r is unknown.

Searches within the r-value range, which must be between the minimum and maximum of the time series to ensure that the series actually exceeds the threshold. The top and bottom 10% of values are then excluded from the search

  1. In this restricted frequency band, TAR model is estimated for different r = YT values.
  2. The value of r is selected to minimize the sum of squares of residuals of the corresponding regression model.

 

Plot (y=y,x=1:length(y),type='o',xlab='t'abline(lq,0,col="blue")  abline(uq,0,col="blue")Copy the code

Sum ((lq <= y) & (y <= uq))Copy the code

80

If d is unknown.

Set d to 1,2,3… , p. Estimate the TAR model for the potential value of each D, and then choose the model with the smallest sum of residual squares.

Chan (1993) has shown that the CLS approach is consistent.

Minimum AIC (MAIC) method

Since in practice the order of AR for these two cases is unknown, a method that allows them to be estimated is needed. For TAR model, for fixed r and D, AIC becomes

The parameters are then estimated by minimizing AIC objects so that the threshold parameters can be searched within a certain time interval so that any scheme has enough data to estimate.

 

#MAIC method for (d in 1:3) {if (model.tar.s$AIC < AIC model.best$d = d model.best$p1 = model.tar.s ar.s$AIC, signif(model.tar.s$thd,4) AICMCopy the code
d AIC R 1 2
1 311.2 1.0020 1 1
2 372.6 0.2218 1 2
3 388.4 1.3870 1 0

Nonlinear test

1. Visual test using lagged regression graph.

Draw Yt with its lag. The fitted regression curve is not very straight, which may indicate the existence of nonlinear relationship.

In the [168] :

lagplot(y)
Copy the code

 

2. Keenan inspection:

Consider the following model caused by second-order Volterra expansion:

The iID normal distribution of {ϵt} is zero mean and finite variance. If η=0, the model becomes an AR (MM) model.

It can be proved that Keenan’s test is equivalent to the test η=0 in the regression model:

Where Yt ^ is from Yt-1… , the fitting value obtained by Yt regression on Yt-m.

3. Tsay test:

A more general alternative to the Keenan test. Substitute a more complex expression for the term η (∑ MJ = 1ϕ JYt-j) 2 in the above model given by Keenan’s test. Finally, F test is performed on the quadratic regression model for which all nonlinear terms are zero.

In the [169] :

Keenan, Tsay #Null is an AR model of order 1 Keenan.test(y,1)Copy the code
$test.stat

90.2589565661567

$p.value

1.76111433596097e-15

$order

1
Copy the code

In the [170] :

Tsay.test(y,1)
Copy the code
$test.stat

71.34

$p.value

3.201e-13

$order

1
Copy the code

4. Check the threshold nonlinearity

This is a test based on likelihood ratio.

The null hypothesis is AR (PP) model; Another assumption is a p-order two-region TAR model with constant noise variance, i.e., σ1=σ2=σ. Using these assumptions, the generic model can be rewritten as

The null hypothesis states that ϕ2,0 = ϕ2,1 =… ϕ2, p = 0.

The likelihood ratio test statistic can be proved to be equal to

Where n-p is the effective sample size, σ^ 2 (H0) is the MLE of the noise variance of linear AR (P) fitting, and σ^ 2 (H1) is the MLE of the noise variance of TAR and the threshold searched at some finite interval.

Under H0, the sampling distribution of likelihood ratio test has nonstandard sampling distribution. See Chan (1991) and Tong (1990).

In the [171] :

Res = TLRT (y, p=1, d=1, a=0.15, b=0.85) resCopy the code
$percentiles 14.1 85.9 $test.statistic: 142.291963130459 $p.value: 0Copy the code

Model diagnosis

Residual analysis was used to complete model diagnosis. The residual of TAR model is defined as

Standardized residuals are the original residuals standardized by the appropriate standard deviation:

If the TAR model is a true data mechanism, the normalized residual graph should appear random. The assumption of independence of standardized errors can be checked by examining the sample ACF of standardized residuals.

 

# Model diagnosis diag(model.tar.best, GOof. Lag =20)Copy the code

 

 

 

 

To predict

The prediction distribution is usually nonnormal. Usually, simulation is used for prediction. Considering the model

Then given Yt = Yt, YT-1 = YT-1,…

Therefore, yt + 1 of the single-step prediction distribution can be achieved by plotting ET + 1 from the error distribution and calculating H (YT, et + 1). .

By repeating this process independently B times, you can get a random sample of B values from the forward-prediction distribution.

The one-step forward forecast mean can be estimated from the sample mean of these B values.

Through iteration, the simulation method can be easily extended to find any L-step to predict the distribution in advance:

Where Yt = Yt and et + 1, et + 2… Et + L is a random sample of LL value obtained from the error distribution.

In the [173] :

Model.tar.pred $pred. Interval [2,], # lines(ts(model.tar.pred$pred. Interval [2,], Start =end(y) + c(0,1), freq=1), lty=2) lines(ts(model)Copy the code

 

 

The sample

The time series simulated here is the annual number of sunspots from 1700 to 1988.

In the [174] :

# Dataset # Sunspot sequence, annual plot.ts(SUNspCopy the code

 

 

 

# Check nonlinear Lagplot (SUNSPO) by hysteresis regression graphCopy the code

 

 

 

Test (sunspot.year) tsay.test (sunspot.year)Copy the code
$test.stat

18.2840758932705

$p.value

2.64565849317573e-05

$order

9

$test.stat

3.904

$p.value

6.689e-12

$order

9
Copy the code

In the [177] :

# MAIC AIC{sunspot.tar.s = tar(sunspot.year, p1 = 9, p2 = 9, d = d, a=0.15, b=0.85Copy the code
d AIC R 1 2
1 2285 22.7 6 9
2 2248 41.0 9 9
3 2226 31.5 7 9
4 2251 47.8 8 7
5 2296 84.8 9 3
6 2291 19.8 8 9
7 2272 43.9 9 9
8 2244 48.5 9 2
9 2221 47.5 9 3

In the [178] :

Sunspot.year, P =9, D =9, A =0.15, b=0.85Copy the code
$percentiles 15 85 $test.statistic: 52.2571950943405 $P.value: 6.8337179274236E-06Copy the code
# Model diagnostics TSDIag (Sunspot.tar.best)Copy the code

 

Best, n.ahead =10, n.sim=1000) lines(TS (sunspot.tar.pred$pretart=e) <- predict(sunspot.tarCopy the code

 

 

 

 

 

Ar. mod < -arima (sunspot.year, order=c(ord,0,0), method="CSS-ML") plot.ts(sunspot.year[10:289]Copy the code

 

 

Simulate AR performance on TAR model

Example 1. Fit AR (4) to TAR model

Set. Seed (12349) # Low mechanism parameter I1 = 0.3 P1 = 0.5 s1 = 1 # High mechanism parameter I2 = -0.2 p2 = -1.8 s2 = 1 Thresh = -1 delay = 1 nobs = 200 Y =sim(n= NObs,Phi1=c(i1, P1),Phi$y ord < -tsay. test(y)$order # pacF (sunspot.year) #try  AR order 4Copy the code

 

 

 

 

 

 

 

Example 2. Fitting AR (4) to TAR model

 

 

 

 

Example 3. Fitting AR (3) to TAR model

 

 

 

 

Example 3. Fitting AR (7) to TAR model

 

 

 

 

 

 

reference

W. Enders, 2010. Apply econometric time series


Most welcome insight

1. Use LSTM and PyTorch for time series prediction in Python

2. Long and short-term memory model LSTM is used in Python for time series prediction analysis

3. Time series (ARIMA, exponential smoothing) analysis using R language

4. R language multivariate Copula – Garch – model time series prediction

5. R language Copulas and financial time series cases

6. Use R language random wave model SV to process random fluctuations in time series

7. Tar threshold autoregressive model for R language time series

8. R language K-Shape time series clustering method for stock price time series clustering

Python3 uses ARIMA model for time series prediction