【问题标题】:Multiple time series in a long format tsibble长格式 tsibble 中的多个时间序列
【发布时间】:2019-11-17 14:53:13
【问题描述】:

我想使用fable 包运行时间序列模型以提前一步进行预测。据我了解,我需要以tsibble 格式保存我的数据。这是我想要做的,

  • 生成三个 id
  • 这三个 ID 的时间戳
  • 三个随机系列
  • tsibble 的身份加入这一切
  • 提前一个月预测

所以我想先创建一个tsibble。为此,我尝试使用以下几行来创建,

ts <- tsibble(
  ids = c(rep(43, 20), rep(33, 20), rep(11, 20)),
  timest = rep(yearmonth("2010 Jan") + 0:19, each = 3),
  data = rnorm(60, mean = 10, sd = 5),
  key = ids
)

使用这个 tsibble 我想运行以下模型,

fit <- ts %>%
  model(
    arima = ARIMA(data)
  )
fit

fc <- fit %>%
  forecast(h = "1 month")
fc

但是,我在创建 tsibble 时遇到问题。我知道我不能重复,但指向key = ids 应该可以解决问题。任何人都可以帮助我找到我正在做的错误吗?

【问题讨论】:

    标签: r fable-r tsibble


    【解决方案1】:

    你快到了。而不是timest = rep(yearmonth("2010 Jan") + 0:19, each = 3) 你需要timest = rep(yearmonth("2010 Jan") + 0:19, times = 3) 时间与id 不一致。每个连续复制“2010 jan”3 次,而不是整个输入重复 3 次。在代表?rep的帮助下查看详细信息

    library(tsibble)
    
    ts <- tsibble(
      ids = c(rep(43, 20), rep(33, 20), rep(11, 20)),
      timest = rep(yearmonth("2010 Jan") + 0:19, times = 3),
      data = rnorm(60, mean = 10, sd = 5),
      key = ids,
      index = timest
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 2021-04-14
      相关资源
      最近更新 更多