Search code examples
rtime-seriesforecasting

Decompose time series using R


I'm new to R.

What I'm trying to do is to decompose a time series, which is given in hourly resolution.

My data looks like this:

Time    traffic
6/7/2005 7:00   56718587433
6/7/2005 8:00   76456162968
6/7/2005 9:00   82534038485
6/7/2005 10:00  88796995092

 ...

7/28/2005 10:00 51528036132
7/28/2005 11:00 69610584123
7/28/2005 12:00 76364975533
7/28/2005 13:00 81281257078

In order to decompose my data to trend, seasonal and stationary components, this is what I tried:

library(xts)
library(forecast)
data<-read.csv("my_file.csv")
data<-ts(data[,2],frequency = 24*365, start=c(2005,6,7,7))
decompose(data)

but this is the error I'm getting:

Error in decompose(data): time series has no or less than 2 period

What am I doing wrong?


Solution

  • When you use frequency = 24*365 you are signaling that you want the unit of time to be years. Since you have less than two months of data, you do not have 2 periods (years). Try using days as your basic unit instead - i.e. try frequency = 24