Fully reproducible example on the public data that can be used to recreate problem is here (I've used the example from [https://otexts.com/fpp2/gts.html] with small adjustment to get negative forecasts):
library(fpp2)
library(hts)
prisonNeg<-prison
prisonNeg[,1]<-seq(nrow(prisonNeg), 1, -1) # just changing this column to get negative predictions from the model
prison.gts <- gts(prisonNeg, characters = c(3,1,9), gnames = c("State", "Gender", "Legal", "State*Gender", "State*Legal", "Gender*Legal"))
modelFcsts<-forecast.gts(prison.gts, h=5, method="comb", fmethod="arima", weights='mint', covariance='shr', keep.fitted = T, keep.resid = T, nonnegative = T)
Hi,
I have created a grouped time series with 2 groups and 3 levels in each. When I pass this data to forecast.gts function error pops up saying:
the code for creating ts:
I've been digging a bit through the source code and I think the issue is in line 281 in [https://github.com/earowang/hts/blob/master/R/forecast-gts.R] where it should state: pfcasts[pfcasts < 0] <- 0
Fully reproducible example on the public data that can be used to recreate problem is here (I've used the example from [https://otexts.com/fpp2/gts.html] with small adjustment to get negative forecasts):