如何为每小时数据创建R TimeSeries

时间:2022-11-21 16:57:15

I have hourly snapshot of an event starting from 2012-05-15-0700 to 2013-05-17-1800. How can I create a Timeseries on this data and perform HoltWinters to it?

我每小时都有一个从2012-05-15-0700到2013-05-17-1800的活动快照。如何在此数据上创建时间序列并对其执行HoltWinters?

I tried the following

我尝试了以下内容

EventData<-ts(Eventmatrix$X20030,start=c(2012,5,15),frequency=8000) 
HoltWinters(EventData)

But I got Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : time series has no or less than 2 periods

但是我在分解时得到了误差(ts(x [1L:wind],start = start(x),frequency = f),季节性):时间序列没有或少于2个周期

What value should I put from Frequency?

我应该从频率中得出什么价值?

2 个解决方案

#1


16  

I think you should consider using ets from the package forecast to perform exponential smoothing. Read this post to have a comparison between HoltWinters and ets .

我认为你应该考虑使用包预测中的ets来执行指数平滑。阅读这篇文章,对HoltWinters和ets进行比较。

require(xts)
require(forecast)

time_index <- seq(from = as.POSIXct("2012-05-15 07:00"), 
                  to = as.POSIXct("2012-05-17 18:00"), by = "hour")
set.seed(1)
value <- rnorm(n = length(time_index))

eventdata <- xts(value, order.by = time_index)
ets(eventdata)

Now if you want to know more about the syntax of ets check the help of this function and the online book of Rob Hyndman (Chap 7 section 6)

现在,如果您想了解有关ets语法的更多信息,请查看此函数的帮助以及Rob Hyndman的在线书籍(第7章第6节)

#2


2  

Please take a look at the following post which might answer the question:

请查看以下可能回答问题的帖子:

Decompose xts hourly time series

分解xts每小时时间序列

Its explains how you can create a xts object using POSIXct objects. This xts object can have its frequency attribute set manually and you will probably then be able to use HoltWinters

它解释了如何使用POSIXct对象创建xts对象。此xts对象可以手动设置其频率属性,然后您可能可以使用HoltWinters

#1


16  

I think you should consider using ets from the package forecast to perform exponential smoothing. Read this post to have a comparison between HoltWinters and ets .

我认为你应该考虑使用包预测中的ets来执行指数平滑。阅读这篇文章,对HoltWinters和ets进行比较。

require(xts)
require(forecast)

time_index <- seq(from = as.POSIXct("2012-05-15 07:00"), 
                  to = as.POSIXct("2012-05-17 18:00"), by = "hour")
set.seed(1)
value <- rnorm(n = length(time_index))

eventdata <- xts(value, order.by = time_index)
ets(eventdata)

Now if you want to know more about the syntax of ets check the help of this function and the online book of Rob Hyndman (Chap 7 section 6)

现在,如果您想了解有关ets语法的更多信息,请查看此函数的帮助以及Rob Hyndman的在线书籍(第7章第6节)

#2


2  

Please take a look at the following post which might answer the question:

请查看以下可能回答问题的帖子:

Decompose xts hourly time series

分解xts每小时时间序列

Its explains how you can create a xts object using POSIXct objects. This xts object can have its frequency attribute set manually and you will probably then be able to use HoltWinters

它解释了如何使用POSIXct对象创建xts对象。此xts对象可以手动设置其频率属性,然后您可能可以使用HoltWinters