R Under development (unstable) (2024-10-26 r87273 ucrt) -- "Unsuffered Consequences"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(tsDyn)
> 
> mod.set <- setar(lynx,m=2)
Warning message:
Possible unit root in the low  regime. Roots are: 0.4681 5.0788 
> 
> regime(mod.set)
Time Series:
Start = 1821 
End = 1934 
Frequency = 1 
  [1] NA NA  1  1  1  2  2  2  2  2  2  1  1  1  1  1  2  2  2  2  1  1  1  1  1
 [26]  1  1  2  2  1  1  1  1  1  1  2  2  2  2  1  1  1  1  1  2  2  2  2  1  1
 [51]  1  1  1  2  2  2  2  1  1  1  1  1  1  2  2  2  2  1  1  1  1  1  1  1  1
 [76]  2  2  1  1  1  1  1  1  2  2  2  2  2  1  1  1  1  2  2  2  2  2  1  1  1
[101]  1  1  1  1  2  2  2  2  1  1  1  1  2  2
> regime(mod.set, initVal=FALSE)
Time Series:
Start = 1823 
End = 1934 
Frequency = 1 
  [1] 1 1 1 2 2 2 2 2 2 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 2 2
 [38] 1 1 1 1 1 2 2 2 2 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1 1 1 2
 [75] 2 1 1 1 1 1 1 2 2 2 2 2 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2
[112] 2
> regime(mod.set, time=FALSE)
  [1] NA NA  1  1  1  2  2  2  2  2  2  1  1  1  1  1  2  2  2  2  1  1  1  1  1
 [26]  1  1  2  2  1  1  1  1  1  1  2  2  2  2  1  1  1  1  1  2  2  2  2  1  1
 [51]  1  1  1  2  2  2  2  1  1  1  1  1  1  2  2  2  2  1  1  1  1  1  1  1  1
 [76]  2  2  1  1  1  1  1  1  2  2  2  2  2  1  1  1  1  2  2  2  2  2  1  1  1
[101]  1  1  1  1  2  2  2  2  1  1  1  1  2  2
> regime(mod.set, time=FALSE, initVal=FALSE)
  [1] 1 1 1 2 2 2 2 2 2 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 2 2
 [38] 1 1 1 1 1 2 2 2 2 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1 1 1 2
 [75] 2 1 1 1 1 1 1 2 2 2 2 2 1 1 1 1 2 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 1 1 1 2
[112] 2
> plot(regime(mod.set))
> 
> data(barry)
> mod.tv <- TVAR(barry[,1:2], lag=2, nthresh=2, thDelay=1, trim=0.1, mTh=1, plot=TRUE)
Best unique threshold 1.2252 
Second best: 1.3893 (conditionnal on th= 1.2252 and Delay= 1 ) 	 SSR/AIC: 6.972166
Second best: 1.2252 (conditionnal on th= 1.3893 and Delay= 1 ) 	 SSR/AIC: 6.972166

Second step best thresholds 1.2252 1.3893 		 SSR: 6.972166 
> 
> regime(mod.tv)
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1973  NA  NA   1   1   1   1   1   1   1   1   1   1
1974   1   1   1   1   1   1   1   1   1   1   1   1
1975   1   1   1   1   1   1   1   1   1   1   1   1
1976   1   1   1   1   1   1   1   1   1   1   1   1
1977   1   1   1   1   1   1   1   1   1   1   1   1
1978   1   1   1   1   1   1   1   1   1   1   1   1
1979   1   1   1   1   1   1   1   1   1   1   1   1
1980   1   1   1   1   1   1   1   1   1   1   1   1
1981   1   1   1   1   1   1   1   1   1   1   1   1
1982   1   1   1   1   1   2   2   2   2   2   2   2
1983   2   2   2   2   2   2   2   2   2   2   2   2
1984   2   2   2   2   2   2   2   2   2   2   2   2
1985   2   2   2   2   2   2   2   2   2   2   2   2
1986   3   3   3   3   2   2   3   2   2   2   2   2
1987   2   2   2   2   2   2   2   2   2   2   2   2
1988   2   2   2   2   2   2   1   1   1   2   1   1
1989   1   1   1   1   1   1   1   1   1   1   1   1
1990   1   1   1   1   1   1   1   1   1   1   1   1
1991   1   1   1   1   1   1   1   1   1   1   1   1
1992   1   1   1   1   1   1   1   1   1   1   2   2
1993   2   2   2   2   2   2   2   2   2   2   2   2
1994   2   2   2   2   2   2   2   2   2   2   2   2
1995   2   3   3   3   2   2   2   2   2   2   2   2
1996   2   2   2   2   2   2   2   2   2   2   2   2
1997   2   2   2   2   3   2   2   2   3   2   2   3
1998   3   3   3   3   3   3   3   3   3   3   3   3
1999   3   3   3   3   3   3   3   3   3   3   3   3
> regime(mod.tv, initVal=FALSE)
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1973           1   1   1   1   1   1   1   1   1   1
1974   1   1   1   1   1   1   1   1   1   1   1   1
1975   1   1   1   1   1   1   1   1   1   1   1   1
1976   1   1   1   1   1   1   1   1   1   1   1   1
1977   1   1   1   1   1   1   1   1   1   1   1   1
1978   1   1   1   1   1   1   1   1   1   1   1   1
1979   1   1   1   1   1   1   1   1   1   1   1   1
1980   1   1   1   1   1   1   1   1   1   1   1   1
1981   1   1   1   1   1   1   1   1   1   1   1   1
1982   1   1   1   1   1   2   2   2   2   2   2   2
1983   2   2   2   2   2   2   2   2   2   2   2   2
1984   2   2   2   2   2   2   2   2   2   2   2   2
1985   2   2   2   2   2   2   2   2   2   2   2   2
1986   3   3   3   3   2   2   3   2   2   2   2   2
1987   2   2   2   2   2   2   2   2   2   2   2   2
1988   2   2   2   2   2   2   1   1   1   2   1   1
1989   1   1   1   1   1   1   1   1   1   1   1   1
1990   1   1   1   1   1   1   1   1   1   1   1   1
1991   1   1   1   1   1   1   1   1   1   1   1   1
1992   1   1   1   1   1   1   1   1   1   1   2   2
1993   2   2   2   2   2   2   2   2   2   2   2   2
1994   2   2   2   2   2   2   2   2   2   2   2   2
1995   2   3   3   3   2   2   2   2   2   2   2   2
1996   2   2   2   2   2   2   2   2   2   2   2   2
1997   2   2   2   2   3   2   2   2   3   2   2   3
1998   3   3   3   3   3   3   3   3   3   3   3   3
1999   3   3   3   3   3   3   3   3   3   3   3   3
> regime(mod.tv, time=FALSE)
  [1] NA NA  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
 [26]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
 [51]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
 [76]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
[101]  1  1  1  1  1  1  1  1  1  1  1  1  1  2  2  2  2  2  2  2  2  2  2  2  2
[126]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2
[151]  2  2  2  2  2  2  3  3  3  3  2  2  3  2  2  2  2  2  2  2  2  2  2  2  2
[176]  2  2  2  2  2  2  2  2  2  2  2  1  1  1  2  1  1  1  1  1  1  1  1  1  1
[201]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
[226]  1  1  1  1  1  1  1  1  1  1  1  1  1  2  2  2  2  2  2  2  2  2  2  2  2
[251]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  3  3  3  2  2  2  2  2  2  2
[276]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  3  2  2  2  3  2  2  3
[301]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
> regime(mod.tv, time=FALSE, initVal=FALSE)
  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[112] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
[149] 2 2 2 2 2 2 3 3 3 3 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
[186] 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[223] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
[260] 2 2 2 2 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 3 2
[297] 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
> plot(regime(mod.tv))
> 
> 
> 
> mod.tvecm <-TVECM(barry[,1:2], nthresh=2,lag=1, ngridBeta=20, ngridTh=30,trim=0.05, common="All")
71 (11.8%) points of the grid lead to regimes with percentage of observations < trim and were not computed
Best threshold from first search -0.0918 
Best cointegrating value 0.01640409 
Second best (conditionnal on the first one) -0.0918 0.2282 	 SSR 7.17416 
There were  6  thresholds values which minimize the SSR in the iterative step, the first one was taken
Second step best thresholds -0.0954 0.2282 			 SSR 7.17416 
> 
> regime(mod.tvecm)
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1973  NA  NA   3   3   3   3   3   3   3   3   3   3
1974   3   3   3   3   3   3   3   3   3   3   3   3
1975   3   3   3   3   3   3   3   3   3   3   3   3
1976   3   3   3   3   3   3   3   3   3   3   3   3
1977   3   3   3   3   3   3   3   3   3   3   3   3
1978   3   3   3   3   3   3   3   3   3   3   3   3
1979   3   3   3   3   3   3   3   3   3   3   3   3
1980   3   3   3   3   3   3   3   3   3   3   3   3
1981   3   3   3   3   3   3   3   2   3   2   2   2
1982   2   2   2   2   2   2   3   2   2   2   2   2
1983   2   2   2   2   2   2   2   2   2   2   2   2
1984   2   2   2   2   2   2   2   2   2   2   2   2
1985   2   2   2   3   2   2   2   2   2   2   2   2
1986   2   2   2   3   2   2   2   2   2   2   2   2
1987   2   2   2   2   2   2   2   2   2   2   2   2
1988   2   2   2   2   2   2   2   2   2   2   2   2
1989   1   1   1   1   1   1   1   1   1   1   1   1
1990   1   1   1   1   1   1   1   1   1   1   1   1
1991   1   1   1   1   1   1   1   1   1   1   1   1
1992   1   1   1   1   1   1   1   1   1   1   1   1
1993   1   1   1   1   1   1   1   1   1   1   1   1
1994   1   1   1   1   1   1   1   1   1   1   1   1
1995   1   1   1   1   1   1   1   1   1   1   1   1
1996   1   1   1   1   1   1   1   1   1   1   1   1
1997   1   1   1   1   1   1   1   1   1   1   1   1
1998   1   1   1   1   1   1   1   1   1   1   1   1
1999   1   1   1   1   1   1   1   1   1   1   1   1
> regime(mod.tvecm, initVal=FALSE)
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1973           3   3   3   3   3   3   3   3   3   3
1974   3   3   3   3   3   3   3   3   3   3   3   3
1975   3   3   3   3   3   3   3   3   3   3   3   3
1976   3   3   3   3   3   3   3   3   3   3   3   3
1977   3   3   3   3   3   3   3   3   3   3   3   3
1978   3   3   3   3   3   3   3   3   3   3   3   3
1979   3   3   3   3   3   3   3   3   3   3   3   3
1980   3   3   3   3   3   3   3   3   3   3   3   3
1981   3   3   3   3   3   3   3   2   3   2   2   2
1982   2   2   2   2   2   2   3   2   2   2   2   2
1983   2   2   2   2   2   2   2   2   2   2   2   2
1984   2   2   2   2   2   2   2   2   2   2   2   2
1985   2   2   2   3   2   2   2   2   2   2   2   2
1986   2   2   2   3   2   2   2   2   2   2   2   2
1987   2   2   2   2   2   2   2   2   2   2   2   2
1988   2   2   2   2   2   2   2   2   2   2   2   2
1989   1   1   1   1   1   1   1   1   1   1   1   1
1990   1   1   1   1   1   1   1   1   1   1   1   1
1991   1   1   1   1   1   1   1   1   1   1   1   1
1992   1   1   1   1   1   1   1   1   1   1   1   1
1993   1   1   1   1   1   1   1   1   1   1   1   1
1994   1   1   1   1   1   1   1   1   1   1   1   1
1995   1   1   1   1   1   1   1   1   1   1   1   1
1996   1   1   1   1   1   1   1   1   1   1   1   1
1997   1   1   1   1   1   1   1   1   1   1   1   1
1998   1   1   1   1   1   1   1   1   1   1   1   1
1999   1   1   1   1   1   1   1   1   1   1   1   1
> regime(mod.tvecm, time=FALSE)
  [1] NA NA  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
 [26]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
 [51]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
 [76]  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3
[101]  3  3  3  2  3  2  2  2  2  2  2  2  2  2  3  2  2  2  2  2  2  2  2  2  2
[126]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  3  2  2
[151]  2  2  2  2  2  2  2  2  2  3  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2
[176]  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  1  1  1  1  1  1  1  1
[201]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
[226]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
[251]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
[276]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
[301]  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1
> regime(mod.tvecm, time=FALSE, initVal=FALSE)
  [1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
 [38] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
 [75] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 2 2 2 2 2 2 2 2
[112] 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2
[149] 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
[186] 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[223] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[260] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[297] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> plot(regime(mod.tvecm))
> 
> proc.time()
   user  system elapsed 
   2.35    0.46    2.81