12

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?

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

What value should I put from Frequency?

R.D
  • 4,781
  • 11
  • 41
  • 58
  • 1
    This [post](http://robjhyndman.com/hyndsight/seasonal-periods/) and this [answer](http://stats.stackexchange.com/a/123010/46401) by Hyndman explains which frequency you should choose. Instead of using `xts` as suggested by @dickoa, you can also use the `msts` function/object from the`forecast`package, with the added benefit, that it allows you to specify multiple seasons/cycles. The package also includes a function `hw` which is convenient wrapper function for `forecast(ets(...))`. – bonna Mar 02 '17 at 17:58

2 Answers2

18

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 .

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)

dickoa
  • 18,217
  • 3
  • 36
  • 50
  • 1
    thanks, but suppose I want to create a TimeSeries using the tf function, for this hourly data, how to proceed. Sorry I am a R newb. – R.D Jun 17 '13 at 20:58
  • 1
    @DotDot `xts` extend the `ts` class and every function which works with `ts` works with regular `xts` object. So basically, there's no need to use `ts` for hourly data. The packages `zoo` or `timeSeries` can be used too to create hourly time series. – dickoa Jun 17 '13 at 21:07
2

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

Decompose xts hourly time series

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

Community
  • 1
  • 1
Samy Geronymos
  • 395
  • 2
  • 5
  • 15
  • This should be a comment! – Paresh Mayani Jul 23 '15 at 12:24
  • 1
    @PareshMayani this poster doesn't have enough reputation to comment. Samy, link-only answers are not a good fit for Stack Overflow. Could you edit your answer to include the details from the linked answer that clarify how it could be used for this question? – josliber Jul 23 '15 at 14:08
  • 1
    @josilber yup agree! I was about to post another comment but then lost the connection! Thanks for putting down a helpful comment. – Paresh Mayani Jul 24 '15 at 04:55