在R中绘制auto.arima前景色时,如何获取在X轴上绘制的实际日期? [英] How to get the actual date plotted in X axis while plotting the auto.arima forecase in R?

查看:82
本文介绍了在R中绘制auto.arima前景色时,如何获取在X轴上绘制的实际日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含"DATE"和"GOLD PRICE"变量的黄金价格数据集.在R中完成所有预处理步骤后,我通过ts或xts函数将数据帧对象转换为时间序列,并通过adf测试.

I have a gold price data set with "DATE" and "GOLD PRICE" variables.After doing all the pre processing steps in R,I convert the data frame object to time series by ts or xts function and check for stationary through adf test.

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

Now by enabling forecast library I run auto.arima function and forecast next ten values.

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)获得日期.但我想从预测中提取它,然后将其绘制在图表中,以便更好地理解.

Now when I plot the forecast I get some values plotted in x instead of actual dates.I am able to get the date from x.xts through index(x.xts). But I want to extract it from forecast to get it plotted in graph for better understanding.

有人用R代码帮助我解决这个问题.

Someone please help me through this with the R codes.

推荐答案

在创建ts(或xts)对象时,需要明确注明日期.使用可复制的示例:

You need to explicitly note the date when creating the ts (or xts) object. Using a reproducible example:

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

这篇关于在R中绘制auto.arima前景色时,如何获取在X轴上绘制的实际日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆