R预测中缺少日期/时间部分的拟合值 [英] Fitted values in R forecast missing date / time component

查看:89
本文介绍了R预测中缺少日期/时间部分的拟合值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用时间序列数据(以XTS格式)在R中进行各种模型的研究,但我一直遇到同样的问题,即拟合值/预测中没有日期/时间成分,因此我无法将它们绘制在与原始数据相同的图上.

I've been doing a variety of models in R with time series data (in XTS format) and I keep running into the same issue where there's no date / time component to the fitted values / forecasts and thus I can't graph them on the same graph as the original data.

使用以下代码,从网上看到的所有内容中,我都应该在同一张图中得到两个折线图.但是,我只是从plot命令中获得了原始图形,并且第二行从不出现.

Using the following code, from everything I see online I SHOULD get two line graphs on the same graph. However, I just get the original graph from the plot command and the second line never appears.

library("stats")
library("forecast")
model_a1 <- auto.arima(GED$Mfg.Shipments.Total..USA.)
plot(GED$Mfg.Shipments.Total..USA.)
lines(fitted(model_a1), col = 2)

如果我仅画出残差:

plot(fitted(model_a1))

我得到一个图形,但是没有日期/时间,它只是在x轴上说索引",范围是0-1,2000.

I get a graph, but instead of having the date / time, it just says "Index" with a range of 0 - 1,2000 on the x-axis.

关于什么原因的任何想法?对于XTS时间序列为何会导致没有日期/时间成分的残差,我什么也找不到.另外,我尝试过发布图片,但显然存在一个愚蠢的规则,即如果您至少发布10次以上,就无法发布图片以进一步说明问题.....

Any ideas as to what's causing this? I can't find anything on why an XTS time series would result in residuals with no date / time component. Also, I tried to post images but apparently there's a silly rule where if you don't post at least 10 times, you can't post images to further explain your problem.....

str(GED) 
An ‘xts’ object on 2018-01-01/2115-12-01 containing: 
Data: num [1:1176, 1:472] NA NA NA NA NA NA NA NA NA NA ... 
  - attr(*, "dimnames")=List of 2 
        ..$ : NULL
        ..$ : chr [1:472] "SRPM..USA." "WTI" "CU..Argentina." "CU..Australia."  
... Indexed by objects of class: [Date] TZ: UTC 
   xts Attributes: NULL

推荐答案

请勿使用绘图中的日期,而将数字序列用作x轴.您可以将日期用作标签.尝试这样的事情:

Do not use the dates in your plot, use a numeric sequence as x axis. You can use the dates as labels. Try something like this:

y=GED$Mfg.Shipments.Total..USA.
n=length(y)
model_a1 <- auto.arima(y)
plot(x=1:n,y,xaxt="n",xlab="")
axis(1,at=seq(1,n,length.out=20),labels=index(y)[seq(1,n,length.out=20)],
     las=2,cex.axis=.5)
lines(fitted(model_a1), col = 2)

取决于您的数据的结果将是类似的:

The result depending on your data will be something similar:

这篇关于R预测中缺少日期/时间部分的拟合值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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