I'm trying to create a bagging algorithm. for this I need to draw random blocks from the whole time series. I created an index vector that contains the random block draws, but when i want to apply it on my zoo time series, i get the
In zoo(rval, index(x)[i]) :
some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique
error. because the sampling uses replacement, i get multiple entries with the same timestamp. i somehow tried converting the data into a matrix that doesn't contain timestamps, but it didn't work out really. i also tried the same thing manually in the console, where i didn't get the warning from the zoo object, but i don't really wanna work around suppressing the error message or anything like that.
this would be the part of the code in question: n = sample size, m = blocksize, b = number of blocks (so that m*b=n). Ypretest and Xpretest are initialized as zoo (but i also tried various other types too, didn't work out either)
if (n%%m == 0) {
b <- n/m
while(tail(blockvector,n=1)+m < n) {
blockvector <- c(blockvector,tail(blockvector,n=1)+m)
}
randomvector <- sample(blockvector, b, replace=T)
for(i in 1:b) {
blockindex <- c(blockindex, randomvector[i]:(randomvector[i]+m-1))
}
Ypretest <- Y[blockindex]
Xpretest <- X[blockindex]
any suggestions?