【问题标题】:hts method for creating hierarchical time series用于创建分层时间序列的 hts 方法
【发布时间】:2021-12-04 23:01:29
【问题描述】:

我正在尝试使用 hts 包将时间序列转换为层次结构,我的结构如下:

我的数据已经以 ts 对象的形式存储在 R 中,每周频率,并且所有列都被标记:

然后我尝试创建 hts 对象,但收到此错误消息,可能是因为我不完全了解如何拆分参数“characters”中的列。

x <- hts(abc, c(1,1,2,2))
Since argument characters are not specified, the default labelling system is used.
Error: Argument nodes must be a list.

提前致谢

【问题讨论】:

    标签: r time-series forecasting


    【解决方案1】:

    首先您需要使用参数characters。这不是hts() 的第二个参数。其次,您需要根据列名指定characters。在这种情况下,第一个字符是第一级分解(A、B、C、D、E),而接下来的两个字符指定下一个分解级。所以你的论点应该是characters = c(1,2)

    这是一个合成数据示例,但结构与您的相同。

    library(hts)
    abc <- matrix(sample(1:100, 32*140, replace=TRUE), ncol=32)
    colnames(abc) <- c(
      paste0("A0",1:5), 
      paste0("B0",1:9),"B10",
      paste0("C0",1:8),
      paste0("D0",1:5),
      paste0("E0",1:4)
    )
    abc <- ts(abc, start=2019, frequency=365.25/7)
    x <- hts(abc, characters = c(1,2))
    x
    #> Hierarchical Time Series 
    #> 3 Levels 
    #> Number of nodes at each level: 1 5 32 
    #> Total number of series: 38 
    #> Number of observations per series: 140 
    #> Top level series: 
    #> Time Series:
    #> Start = 2019 
    #> End = 2021.66392881588 
    #> Frequency = 52.1785714285714 
    #>   [1] 1735 1645 1472 1638 1594 1722 1525 1761 1500 1746 1331 1567 1853 1652 1587
    #>  [16] 1540 1453 1989 1629 1587 1596 1474 1320 1599 1762 1419 1931 1447 2102 1608
    #>  [31] 1439 1909 1331 1742 1428 1677 1534 1657 1741 1612 1574 1954 1542 2067 1512
    #>  [46] 1850 1650 1666 1321 1332 1924 1786 1496 1695 1363 1437 1740 1448 1260 1371
    #>  [61] 1661 1726 1786 1641 1463 1616 1641 1895 1503 1430 1972 1705 1722 1447 1515
    #>  [76] 1636 1544 1727 1960 1647 1682 1569 1616 1628 1706 1837 1738 1659 1574 1716
    #>  [91] 1409 1428 1411 1708 1606 1501 1413 1707 1552 1567 1693 1748 2034 1557 1402
    #> [106] 1649 1637 1653 1857 1401 1519 1600 1844 1585 1796 1612 1456 1626 1390 1368
    #> [121] 1492 1765 1644 1773 1302 2027 1810 1652 1819 1628 1574 1655 1650 1817 1605
    #> [136] 1422 1793 1999 1489 1667
    

    reprex package (v2.0.1) 于 2021 年 10 月 18 日创建

    【讨论】:

      猜你喜欢
      • 2015-05-02
      • 1970-01-01
      • 2014-10-26
      • 2021-10-26
      • 1970-01-01
      • 2016-01-08
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多