0

I am using betategarch package and when I use predict function it gives me error subscript out of bounds. I have researched it and did not get any results so far because this error is very general and I am not sure what to do and how to solve it. I also used (any(is.na) function to check if I had any NA's because that was one of the proposition to solve my problem, but I did not have any missing values.

  LOTOS.daily.xts
                   [,1]
2005-06-10 -0.016807118
2005-06-13  0.006756782
2005-06-14  0.000000000
2005-06-15  0.000000000
2005-06-16 -0.016978337
2005-06-17 -0.003430535
2005-06-20 -0.003442344
2005-06-21  0.000000000
2005-06-22  0.027212564
2005-06-23 -0.006734032
2005-06-24 -0.006779687
2005-06-27  0.010152371
2005-06-28  0.000000000
2005-06-29 -0.003372684
2005-06-30  0.000000000

    str(LOTOS.daily.xts)
An ‘xts’ object on 2005-06-10/2005-06-30 containing:
  Data: num [1:15, 1] -0.01681 0.00676 0 0 -0.01698 ...
  Indexed by objects of class: [POSIXct,POSIXt] TZ: 
  xts Attributes:  
 NULL

Fitting my data:

Lotos.comp1 <- tegarch(LOTOS.daily.xts)
lotos.comp1.stdev <- fitted(Lotos.comp1)

Predicting:

set.seed(123)
predict(Lotos.comp1, n.ahead=60)

predict(Lotos.comp1, n.ahead=5)
Error in predict.tegarch(Lotos.comp1, n.ahead = 5) : 
  subscript out of bounds

Thank you

Serdar
  • 87
  • 1
  • 1
  • 6
  • 1
    The information is not sufficient for anyone else to reproduce the error. Please provide a small subset of data that can reproduce the problem you are experiencing. See [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more information. – MrFlick May 13 '14 at 18:20
  • Thank you for the answer, but I was wondering how big I need to include the data, I have a daily data starting from 2005. Maybe be I can upload my data here somehow? – Serdar May 13 '14 at 19:40
  • It's best just to post as little as possible data to reproduce the error. It doesn't have to be real data. As the link shows, you can create a fake data set with random values if that's easier. If you require someone to download data from somewhere else, you are less likely to get a response. – MrFlick May 13 '14 at 19:46
  • Thank you. I added the minimal data to reproduce my error. – Serdar May 13 '14 at 20:03
  • 1
    Also, as a graduate from UofM I have to say go BLUE! – Serdar May 13 '14 at 20:36

2 Answers2

0

As far as I can tell this is clearly a bug in the package. I think it's expecting the response variable to be named "y" but that doesn't make any sense and even when that's the case, the result is wrong, It appears to be a problem with the initial values that predict.tegarch takes. It tries to pull them from the model. I got this to work for me

Lotos.comp1 <- tegarch(LOTOS.daily.xts)
lotos.comp1.stdev <- fitted(Lotos.comp1)

cd <- coredata(fitted(Lotos.comp1, verbose=T))
initv <- data.frame(cd[,c(1, match(c("lambda", "lambdadagg"), colnames(cd)))])
names(initv)[1]<-"y"

predict(Lotos.comp1, initial.values=initv)

I'm not sure that I grabbed the correct value for the initial value. I really have no idea how this particular regression works. There are other unnamed column in the cd matrix that could be the "y" value it's looking for as well, but it kind of makes sense that those are the first values that you entered into the model.

So, like I said, this makes the error go away but i can't be certain it gives the correct answer. I would definitely contact the package author with this reproducible but of code to see if they are aware of the problem as well. (FYI, I figured this out looking at the source of the function which you can find with getAnywhere("predict.tegarch")).

MrFlick
  • 195,160
  • 17
  • 277
  • 295
0

I have contacted the author of the package Mr.Sucarrat and he kindly explained the error of that I have having. The problem comes from me using an xts object or specific construction of xts and not zoo. His package works well with zoo package. So if anyone had the same error I hope this helped. Also, thank's to Mr. Genaro Sucarrat for very quick response and the help with this error.

Serdar
  • 87
  • 1
  • 1
  • 6