简体   繁体   English

通过示例在 R 中使用时间序列进行预测的问题

[英]Question with using time series in R for forecasting via example

Im working through this example .我正在研究这个例子 However, when I begin investigating the tk_ts output I don't think it is taking the start/end data Im entering correctly, but am unsure as to what the proper input is if I want it to start at 12-31-2019 and end at 7-17-2020:但是,当我开始调查 tk_ts output 时,我认为它没有正确输入我输入的开始/结束数据,但如果我希望它在 2019 年 12 月 31 日开始并结束,我不确定正确的输入是什么在 2020 年 7 月 17 日:

daily_cases2 <- as_tibble(countrydatescases) %>%
    mutate(Date = as_date(date)) %>%
    group_by(country, Date) %>%
    summarise(total_cases = sum(total_cases))

  daily_cases2$total_cases <- as.double(daily_cases2$total_cases)
  
  # Nest
  daily_cases2_nest <- daily_cases2 %>%
    group_by(country) %>%
    tidyr::nest()
  
# TS
  daily_cases2_ts <- daily_cases2_nest %>%
    mutate(data.ts = purrr::map(.x  = data, 
                         .f       = tk_ts, 
                         select   = -Date,
                         start    = 2019-12-31,
                         freq     = 1))

Here is what I get when I examine it closely:这是我仔细检查后得到的结果:

在此处输入图像描述

在此处输入图像描述

When I go through the example steps with these parameters the issue is also then seen in the subsequent graph:当我使用这些参数通过示例步骤 go 时,问题也出现在下图中:

在此处输入图像描述

I've tried varying the frequency and start parameters and its just not making sense.我试过改变频率和启动参数,但它只是没有意义。 Any suggestions?有什么建议么?

You've given the start and end dates, but you haven't said what frequency you want.你已经给出了开始和结束日期,但你没有说你想要什么频率。 Given that you want the series to start at the end of 2019 and end in the middle of July, 2020, I'm guessing you want a daily time series.鉴于您希望该系列在 2019 年底开始并在 2020 年 7 月中旬结束,我猜您想要一个每日时间序列。 In that case, the code should be:在这种情况下,代码应该是:

daily_cases2_ts <- daily_cases2_nest %>%
    mutate(data.ts = purrr::map(.x  = data, 
                         .f       = tk_ts, 
                         select   = -Date,
                         start    = c(2019, 365),  # day 365 of year 2019
                         freq     = 365))          # daily series

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

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