ellisp / forecastxgb-r-package

An R package for time series models and forecasts with xgboost compatible with {forecast} S3 classes
GNU General Public License v3.0
140 stars 42 forks source link

Maxlag is negative for short time series #44

Open Ic3fr0g opened 6 years ago

Ic3fr0g commented 6 years ago

I tried running xgbar on a small time series -

y <- structure(c(11.3709584471467, 9.43530182860391, 10.3631284113373, 
10.632862604961, 10.404268323141, 9.89387548390852, 11.5115219974389, 
9.9053409615869, 12.018423713877, 9.93728590094758, 11.3048696542235, 
12.2866453927011, 8.61113929888766), .Tsp = c(1, 2, 12), class = "ts")

xgbar(y)

Executes with the following error -

Error in [.default(origy, -(1:(maxlag))) : only 0's may be mixed with negative subscripts In addition: Warning message: In xgbar(y) : y is too short for 24 to be the value of maxlag. Reducing maxlags to -2 instead.

I think this error can be fixed with a simple check for negative maxlag. https://github.com/ellisp/forecastxgb-r-package/blob/fe2894aa43a1805b94c881a32f7a5291e53654d6/pkg/R/xgbar.R#L166

if (maxlag < 0 ) {
    stop('Try a longer time-series as maxlag is negative')
}