tsDyn icon indicating copy to clipboard operation
tsDyn copied to clipboard

SETAR predict not working with "none"

Open TheBridgeTroll opened this issue 3 years ago • 3 comments

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

TheBridgeTroll avatar May 29 '22 23:05 TheBridgeTroll

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)

MatthieuStigler avatar May 30 '22 06:05 MatthieuStigler

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

TheBridgeTroll avatar May 30 '22 09:05 TheBridgeTroll

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.

MatthieuStigler avatar May 30 '22 13:05 MatthieuStigler