包寓言的预测功能似乎对日期(索引)有奇怪的影响
# build a simple tible
> df <- tibble(
d = seq.Date(ymd('2018-02-12'), by = 7 , length = n ),
x = seq_len(10))
# convert dates to yearweek objects
> df <- df %>%
mutate(d = yearweek(d))
# build the tsibble
> ts <- as_tsibble(df, index = d)
> ts
# A tsibble: 10 x 2 [1W]
d x
<week> <int>
1 2018 W07 1
2 2018 W08 2
3 2018 W09 3
4 2018 W10 4
5 2018 W11 5
6 2018 W12 6
7 2018 W13 7
8 2018 W14 8
9 2018 W15 9
10 2018 W16 10
适合任何型号
> fm <- model(ts, ETS(x))
并预测它
> fore <- forecast(fm , h = 4)
> fore
# A fable: 4 x 4 [1W]
# Key: .model [1]
.model d x .distribution
<chr> <date> <dbl> <dist>
1 ETS(x) 2018-04-23 11.0 N(11, 3.7e-05)
2 ETS(x) 2018-04-30 12.0 N(12, 1.5e-04)
3 ETS(x) 2018-05-07 13.0 N(13, 3.9e-04)
4 ETS(x) 2018-05-14 14.0 N(14, 8.2e-04)
如您所见,索引变量具有不同的格式
> class(ts$d)
[1] "yearweek" "Date"
> class(fore$d)
[1] "Date"
知道为什么会发生所有这些以及如何避免它吗?
在此先感谢您的任何建议...