MatthieuStigler / tsDyn

tsDyn
tsdyn.googlecode.com
33 stars 20 forks source link

SETAR predict not working with "none" #43

Open Fatafim opened 2 years ago

Fatafim commented 2 years ago

Hello! The case is pretty simple. Say I define a simple SETAR model:

set <- setar(training, m=1, nthresh = 1, include = "const") and then I'm trying to calculate a prediction from that: > predict(set, n.ahead = 1) Time Series: Start = 80 End = 80 Frequency = 1 [1] -1.083009 everything works just fine. However the same code with include="none":

set <- setar(training, m=1, nthresh = 1, include = "none") predict(set, n.ahead = 1) Time Series: Start = 80 End = 80 Frequency = 1 [1] NaN

I really don't think it's the fault of the data (this error has been occurring to me multiple times on different datasets) so if I'm not doing anything wrong (am I?) I think that this is a bug that will need some attention.

Hope you have a nice day!


PS: the dataset I'm using is the datasets::lynx

MatthieuStigler commented 2 years ago

Bug confirmed (see reprex below), thanks for the report!

library(tsDyn)
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
x <- log(lynx)
set2 <- setar(x, m=1, nthresh = 1, include = "none")
#> Warning: Possible unit root in the low regime. Roots are: 0.9646
predict(set2)
#> Time Series:
#> Start = 1935 
#> End = 1935 
#> Frequency = 1 
#> [1] NaN

Created on 2022-05-30 by the reprex package (v2.0.1)

Fatafim commented 2 years ago

You're welcome! Any chance for a quick update?

MatthieuStigler commented 2 years ago

I am afraid not, as I have very little bandwidth currently, and the issue is bigger than I thought: the current code uses the old oneStep, while it should use setar.gen.

If you need the code sooner, you can just see how predict.TVAR uses TVAR.gen (likewise for predict.VAR and VAR.gen), to adapt it to predicta setar model. Literally all you have to do is to feed in the correct initial values and decide on which innovations to use.