[英]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.