我正在尝试按照Rob Hyndman 的 Rstudio.conf 研讨会的方式进行分层预测,但遇到了一些问题。这是我的代码:
library(dplyr)
library(tsibbledata)
library(tsibble)
library(fable)
aus_retail_2013_tr <- aus_retail %>%
filter(Month <= yearmonth("2013 Dec"))
aus_retail_2013_vl <- aus_retail %>%
filter(Month > yearmonth("2013 Dec"))
hmod <- aus_retail_2013_tr %>%
aggregate_key(State*Industry, Turnover=sum(Turnover)) %>%
model(ar=ARIMA(log(Turnover))) %>%
reconcile(ar_adj=min_trace(ar))
fcasts_hmod <- forecast(hmod, aus_retail_2013_vl)
fcasts_hmod %>%
filter(is_aggregated(Industry), State == "Victoria") %>%
autoplot()
Run Code Online (Sandbox Code Playgroud)
该图的输出如下。
我的主要问题是:
ar和ar_adj线是相同的。我该如何解决这些问题?后一个可能是因为并非所有时间序列都涵盖整个时期,但我怎样才能reconcile不跳过缺失的时期?
这是 dplyr 0.8.5、fable 0.2.0、fabletools 0.1.3 和 tsibble 0.8.6。我在 Ubuntu/R 3.6.3 和 Windows 10/R 4.0.0 …
在 R 中搜索时间序列数据的线性插值时,我经常na.approx()从zoo包中找到要使用的建议。
然而,对于不规则的时间序列,我遇到了问题,因为插值在间隙数量上均匀分布,没有考虑该值的关联时间戳。
我找到了一个围绕使用的解决方案approxfun(),但我想知道是否有一个更干净的解决方案,最好基于tsibble具有tidyverts包系列函数的对象?
以前的答案依赖于通过填补空白将不规则日期网格扩展为规则网格。然而,当插值期间应考虑白天时,这会导致问题。
这是一个(修订后的)最小示例,其中包含 POSIXct 时间戳而不是仅日期:
library(tidyverse)
library(zoo)
df <- tibble(date = as.POSIXct(c("2000-01-01 00:00", "2000-01-02 02:00", "2000-01-05 00:00")),
value = c(1,NA,2))
df %>%
mutate(value_int_wrong = na.approx(value),
value_int_correct = approxfun(date, value)(date))
# A tibble: 3 x 4
date value value_int_wrong value_int_correct
<dttm> <dbl> <dbl> <dbl>
1 2000-01-01 00:00:00 1 1 1
2 2000-01-02 02:00:00 NA 1.5 1.27
3 2000-01-05 00:00:00 2 2 2
Run Code Online (Sandbox Code Playgroud)
有什么想法如何(有效)处理这个问题吗?感谢您的支持!