简体   繁体   English

如何使用寓言 package 在 R 中的分层系列中实现回归器?

[英]How to implement regressors in a Hierarchical Series in R, with the Fable package?

I am new to exploring the fable package, and I was wanting to implement Regressors in a Hierarchical Time Series model.我是探索寓言 package 的新手,我想在分层时间序列 model 中实现回归器。 How should the Dimensionality of the data be?数据的维度应该如何? Should there be an additional column inside the tsibble object? tsibble object 内是否应该有一个额外的列? For example, in an ARIMA model.例如,在 ARIMA model 中。 Thank you very much in advance.非常感谢您提前。

The approach for modelling hierarchical data with exogenous regressors is the same as modelling regular data.使用外生回归量对分层数据建模的方法与对常规数据建模的方法相同。 The exogenous regressors should be a column of the tsibble object used to estimate the model, for each node in the hierarchy.对于层次结构中的每个节点,外生回归量应该是用于估计 model 的 tsibble object 的列。

The code below shows how a simple hierarchy ( T = M + F ) can be modelled with a dynamic regression model (ARIMA with xreg).下面的代码显示了如何使用动态回归 model(带有 xreg 的 ARIMA)对简单的层次结构 ( T = M + F ) 进行建模。 Note that the exogenous regressors are just white noise here, but you would use some real data here.请注意,外生回归量在这里只是白噪声,但您将在此处使用一些真实数据。

library(fable)
#> Loading required package: fabletools
library(dplyr)
my_data <- as_tsibble(cbind(mdeaths, fdeaths)) %>% 
  aggregate_key(key, value = sum(value)) %>% 
  # Add the regressor (if you have this in your data, could aggregate it above)
  # If the data is pre-aggregated, specify which keys are <aggregated> with agg_vec().
  mutate(my_xreg = rnorm(nrow(.)))
my_data
#> # A tsibble: 216 x 4 [1M]
#> # Key:       key [3]
#>       index key          value my_xreg
#>       <mth> <chr*>       <dbl>   <dbl>
#>  1 1974 Jan <aggregated>  3035  -1.87 
#>  2 1974 Feb <aggregated>  2552   1.93 
#>  3 1974 Mar <aggregated>  2704  -0.420
#>  4 1974 Apr <aggregated>  2554   0.332
#>  5 1974 May <aggregated>  2014  -1.10 
#>  6 1974 Jun <aggregated>  1655   1.22 
#>  7 1974 Jul <aggregated>  1721   1.68 
#>  8 1974 Aug <aggregated>  1524  -1.46 
#>  9 1974 Sep <aggregated>  1596   0.620
#> 10 1974 Oct <aggregated>  2074  -0.505
#> # … with 206 more rows
my_data %>% 
  model(ARIMA(value ~ my_xreg))
#> # A mable: 3 x 2
#> # Key:     key [3]
#>   key                        `ARIMA(value ~ my_xreg)`
#>   <chr*>                                      <model>
#> 1 fdeaths      <LM w/ ARIMA(0,0,0)(1,1,1)[12] errors>
#> 2 mdeaths      <LM w/ ARIMA(0,0,2)(0,1,2)[12] errors>
#> 3 <aggregated> <LM w/ ARIMA(0,0,2)(2,1,0)[12] errors>

Created on 2021-01-13 by the reprex package (v0.3.0)reprex package (v0.3.0) 于 2021 年 1 月 13 日创建

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将回归变量[xreg / newxreg]添加到分层时间序列预测方法[forecast.hts]? - How to add regressors[xreg/newxreg] to a hierarchical time series forecast method[forecast.hts]? 如何使用 fable::VAR 对滞后的外部回归变量进行预测 - How to forecast with lagged external regressors using fable::VAR 使用寓言包对每月时间序列进行交叉验证 - Cross validation of monthly time series using fable package R:通过寓言,斜纹和地图预测多个时间序列 - R: Forecasting multiple time series with fable, tsibble and map 寓言能否调和层次结构时间序列,其中层次结构在不同节点具有不同的深度? - Can fable reconcile hierarchical time series, where the hierarchy has different depth at different nodes? 如何将寓言/预测(在 R 中)应用于该数据库? - How to apply Fable/Forecast (in R) to this database? 从 hts2 package:VaughanR0/Streamline-R 获取预测区间:分层和分组时间序列 - Get Prediction Intervals from hts2 package:VaughanR0/Streamline-R: Hierarchical and Grouped Time Series R 中寓言包中的 ETS(我可以不用 tsibble 来做) - ETS from fable package in R (can I do it with out tsibble) gts() 来自 hts package:如何创建严格分层的时间序列,以便应用自上而下的分层预测方法 - gts() from hts package: How to create strictly hierarchical time series, in order to apply the top down hierarchical forecasting method R中的分层时间序列 - 创建节点(HTS) - Hierarchical Time Series in R - Creating nodes (HTS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM