Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hts cannot create a hierarchical time series for a single observation #57

Closed
mahdiabolghasemi opened this issue Aug 2, 2020 · 1 comment

Comments

@mahdiabolghasemi
Copy link

It seems that hts cannot create a hierarchical time series if we have only one observation in the series.
It returns: Error in if (nbts <= 1L) { : argument is of length zero

library(hts)

nodes <- list(2, c(3, 2))
abc <- ts(5 + matrix(sort(rnorm(500)), ncol = 5, nrow = 100))
y <- hts(abc[1,], nodes)

@earowang
Copy link
Owner

earowang commented Aug 2, 2020

You need to subset with drop = FALSE to retain the ts object, otherwise abc[1, ] is a numeric vector, not an mts.

library(hts)
#> Loading required package: forecast
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo

nodes <- list(2, c(3, 2))
abc <- ts(5 + matrix(sort(rnorm(500)), ncol = 5, nrow = 100))
hts(abc[1, , drop = FALSE], nodes)
#> Since argument characters are not specified, the default labelling system is used.
#> Hierarchical Time Series 
#> 3 Levels 
#> Number of nodes at each level: 1 2 5 
#> Total number of series: 8 
#> Number of observations per series: 1 
#> Top level series: 
#> Time Series:
#> Start = 1 
#> End = 1 
#> Frequency = 1 
#> [1] 22.10018

Created on 2020-08-03 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants