earowang / hts

Hierarchical and Grouped Time Series
http://pkg.earo.me/hts
110 stars 36 forks source link

Error with hts forecasting with 2 levels #69

Open felixfesca opened 6 months ago

felixfesca commented 6 months ago

I get the following error for a hierarchcial model with only two levels (i.e. top and bottom level) if I try to apply the forecast function to an hts object: Fehler in utmat %*% fcasts : non-conformable arguments Zusätzlich: Warnmeldung: In cbind.Matrix(x, y, deparse.level = 0L) : number of rows of result is not a multiple of vector length

I'm relatively sure that this code still worked about a year ago. The error does also not occur for a hierarchie with 3 or more levels.

library(hts)
my_ts <- replicate(4, arima.sim(model = list(c(ma=0.8,alpha=1,beta=0)),n=12))
my_hts <- hts(my_ts)
forecast.gts(my_hts, h = 4)
ShanikaLW commented 5 months ago

It works for me. See below.

library(hts)
#> Loading required package: forecast
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
set.seed(123)
my_ts <- replicate(4, arima.sim(model = list(c(ma = 0.8)), n = 12))
my_hts <- hts(my_ts)
#> Since argument characters are not specified, the default labelling system is used.
forecast.gts(my_hts, h = 4)
#> Hierarchical Time Series 
#> 2 Levels 
#> Number of nodes at each level: 1 4 
#> Total number of series: 5 
#> Number of observations in each historical series: 12 
#> Number of forecasts per series: 4 
#> Top level series of forecasts: 
#> Time Series:
#> Start = 13 
#> End = 16 
#> Frequency = 1 
#> [1] 0.08870912 0.08870912 0.08870912 0.08870912

Created on 2024-05-31 with reprex v2.1.0