简体   繁体   English

长格式 tsibble 中的多个时间序列

[英]Multiple time series in a long format tsibble

I want to run time series models to forecast one step ahead using fable package.我想使用fable package 运行时间序列模型来预测提前一步。 As far I understand, I need to have my data in tsibble format.据我了解,我需要以tsibble格式保存我的数据。 Here is what I am trying to do,这是我想要做的,

  • Generate three ids生成三个id
  • Time stamps for those three ids这三个 id 的时间戳
  • Three random series三随机系列
  • Join it all as a tsibble加入这tsibble
  • One month ahead forecast提前一个月预测

So I want to make a tsibble first.所以我想先做一个tsibble To do that I am trying to create by using the following lines,为此,我尝试使用以下几行来创建,

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
)

Using this tsibble I want to run the following models,使用这个 tsibble 我想运行以下模型,

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

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

However, I am having problem in creating tsibble .但是,我在创建tsibble时遇到问题。 I know that I cannot have duplicates but pointing key = ids should solve the problem.我知道我不能重复,但指向key = ids应该可以解决问题。 Anybody can help me to find the mistake I am doing?任何人都可以帮助我找到我正在做的错误吗?

You are almost there.你快到了。 Instead of timest = rep(yearmonth("2010 Jan") + 0:19, each = 3) you need timest = rep(yearmonth("2010 Jan") + 0:19, times = 3) The times were not aligned with the id's.而不是timest = rep(yearmonth("2010 Jan") + 0:19, each = 3)您需要timest = rep(yearmonth("2010 Jan") + 0:19, times = 3)时间与身份证。 each replicates the "2010 jan" 3 times in a row, instead of the whole input repeated 3 times.每个连续复制“2010 jan”3 次,而不是整个输入重复 3 次。 See the details with the help of rep ?rep在 rep ?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
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM