Search code examples
rtime-seriesfrequency

R times series frequency


I have a time series data set which consists of 374 days of data points (1 data point for each day). I am struggling to understand the frequency parameter in ts function, so I left it empty:

ts_0615391206 <- ts(demand_rev_0615391206$estimated_demand,
                    start=as.Date(min(demand_rev_0615391206$date),format = "d%/m%/Y%"),
                    end=as.Date(max(demand_rev_0615391206$date),format = "d%/m%/Y%"),
                    #frequency = 1
                    ) 

plot.ts(ts_0615391206) enter image description here however, when I try to decompose using:

ts_0615391206_components <- decompose(ts_0615391206)

I am getting the error:

Error in decompose(ts_0615391206) : 
  time series has no or less than 2 periods

How do I decide how many period there are in my data and consequently what us the parameter "frequency" value should be?

> dput(head(ts_0615391206))
c(2.71, 2.47, 3.86, 3.61, 5.78, 5.59)
> 
> str(ts_0615391206)
 Time-Series [1:194] from 16125 to 16318: 2.71 2.47 3.86 3.61 5.78 5.59 3.28 3.4 3.34 3.68 ...

Solution

  • Per the documentation ?ts:

    ...one could use a value of 7 for frequency when the data are sampled daily, and the natural time period is a week, or 12 when the data are sampled monthly and the natural time period is a year. Values of 4 and 12 are assumed in (e.g.) print methods to imply a quarterly and monthly series respectively.

    Try setting frequency = 7.