【问题标题】:How to get the actual date plotted in X axis while plotting the auto.arima forecase in R?在 R 中绘制 auto.arima 预测时,如何在 X 轴上绘制实际日期?
【发布时间】:2017-04-11 10:08:12
【问题描述】:

我有一个带有“日期”和“黄金价格”变量的黄金价格数据集。在 R 中完成所有预处理步骤后,我通过 ts 或 xts 函数将数据框对象转换为时间序列,并通过adf 测试。

现在通过启用预测库,我运行 auto.arima 函数并预测接下来的十个值。

x <- "DATE"         "GOLD PRICE"
      01-01-2006        1326

x.xts <- xts(x$GOLD PRICE,X$DATE),
fit <- auto.arima(x.xts)
forecast <- forecast(fit,h=10)

现在,当我绘制预测时,我得到了一些用 x 绘制的值而不是实际日期。我能够从 x.xtsindex(x.xts) 获取日期。但我想从预测中提取它以将其绘制在图表中以便更好地理解。

请有人用 R 代码帮我解决这个问题。

【问题讨论】:

  • 请始终包含您正在使用的库——在这种情况下是forecastxts

标签: r plot forecasting


【解决方案1】:

您需要在创建ts(或xts)对象时明确注明日期。使用可重现的示例:

library("forecast")
data("gas") 
# gas is already a TS object. 
# We remove it and recreate it to show the appropriate method
gas2 <- vector(gas); rm(gas)
gas <-  ts(gas2, start= c(1956,1), frequency= 12)
fit <- auto.arima(gas)
forecast(fit, h= 10)
         Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
Sep 1995       57178.66 54885.61 59471.71 53671.74 60685.58
Oct 1995       53080.77 50466.09 55695.46 49081.96 57079.59
Nov 1995       50940.76 48086.64 53794.87 46575.77 55305.75
Dec 1995       40923.84 37931.85 43915.84 36347.99 45499.70
Jan 1996       43739.23 40654.37 46824.09 39021.35 48457.12
Feb 1996       43706.56 40557.77 46855.34 38890.91 48522.20
Mar 1996       47849.24 44653.96 51044.52 42962.48 52736.00
Apr 1996       50204.88 46974.32 53435.44 45264.16 55145.60
May 1996       56691.41 53432.91 59949.91 51707.96 61674.86
Jun 1996       61053.42 57771.93 64334.92 56034.81 66072.04

【讨论】:

  • FIT_FORECAST FIT_FORECAST点预测LO 80 HI 80 LO 95 HI 95 23889.010122012010701201999012019801C123981C122019801C123981 1175.967 1239.995 1159.020 1256.942 我在这里得到了预测,但日期不明确。我想要您示例中的日期而不是值。
  • @JenniferTherese 欢迎来到 SO!请编辑您的 OP 以提供reproducible example
猜你喜欢
  • 1970-01-01
  • 2016-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-16
相关资源
最近更新 更多