【问题标题】:tsibble with 2 keys (not hierarchy) having the week of the year as index具有 2 个键(不是层次结构)的 tsibble,以一年中的一周为索引
【发布时间】:2019-07-27 11:36:07
【问题描述】:

谁能给一些关于如何构建 tsibble 的建议?

我有一个包含四个原始列的日期集:产品、市场、价格、日期 我想构造一个 tsibble 对象。 我将key=id(product,market) 和“一周中的年份”作为索引。 然后我可以预测每个市场中每种产品的价格基准线。

如果你使用nycflights13::weather数据集,我可以使用key=id(origin,year)(这里我没有市场所以用年份来代表市场)。

然后有idex=week(year+month+day)。然后我可以将年、月、日列组合为日期,然后计算week(),然后将年和周加在一起作为'weekyear'并将其设置为索引,然后使用median(temp) 作为该年周。 在这个数据集改革之后,我可以有一个能够预测未来 2-4 周温度的 tsibble。

【问题讨论】:

    标签: r time-series forecast


    【解决方案1】:

    看起来您想先将date 变量转换为yearweek 类。可以吗

    library(tsibble)
    data %>%
      mutate(index = yearweek(date)) %>%
      as_tsibble(key = id(product, market), index = index)
    

    【讨论】:

    • 我收到了这个错误:> dft_ts % + mutate(index = yearweek(date)) %>% + as_tsibble(key = id(artikel_id, market), index = index)错误:有效的 tsibble 必须具有由键和索引标识的不同行。请使用duplicates()检查重复行。
    • 这有效:dft_ts % mutate(yw=yearweek(date)) %>% group_by(yw,artikel_id,market) %>% summarise(avg_w_pric=mean(med_pric)) %>% ungroup() %>% as_tsibble(key = id(artikel_id, market), index = yw)
    猜你喜欢
    • 2019-09-30
    • 2016-08-20
    • 1970-01-01
    • 2011-05-26
    • 2012-09-09
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多