无法在R中进行每日时间序列分析

时间:2015-06-29 01:00:21

标签: r time-series regression forecasting

以下是我的数据

 day       sum
2015-03-05   44           
2015-03-06   46           
2015-03-06   48           
2015-03-07   48           
2015-03-08   58           
2015-03-09   58           
2015-03-10   66           
2015-03-11   68           
2015-03-12   85           
2015-03-13   94           
2015-03-14   98           
2015-03-15  102           
2015-03-16  102           
2015-03-17  104           
2015-03-17  114 

使用的变量类型如下,

typeof(x)
[1] "list"

typeof(x$day)
[1] "double"

typeof(x$sum)
[1] "integer"

class(x$day)
[1] "Date"

我想预测,对于特定的未来日期,总和是多少。

以下是我的发现,

当我使用ts(x)时,日期的值会发生如下变化,

day

16464              

16465              

16466

16467

16468

16469

16470

16471

16472

当我使用ets时,以下是输出,

fit <- ets(x)
Error in ets(ana) : y should be a univariate time series

我可以用总和绘制日期并完美地获得图表。但是,在此之后我无法进行任何分析。我想预测,对于特定的未来日期,总和是多少。我也尝试过回归分析,但它不适用于这个变量。有人可以帮我进一步了解吗?

由于

1 个答案:

答案 0 :(得分:4)

如果您“更正”重复日期,您将能够执行此操作:

library(xts)
dates=as.Date(x$day,"%Y-%m-%d")
xs=xts(x$sum,dates)
plot(xs)
library("forecast")
class(xs)
fit <- ets(xs)
plot(forecast(fit))

enter image description here

相关问题