0
votes

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 ...
4

4 Answers

1
votes

ts_06153912061 <- ts(ts_0615391206, start = c(1999,1), frequency = 365) for Daily

ts_06153912061 <- ts(ts_0615391206, start = c(1999,1), frequency = 52) for Weekly

ts_06153912061 <- ts(ts_0615391206, start = c(1999,1), frequency = 12) for Monthly

ts_06153912061 <- ts(ts_0615391206, start = c(1999,1), frequency = 4) for Quarterly

ts_06153912061 <- ts(ts_0615391206, start = c(1999,1), frequency = 1) for Yearly or Annually

0
votes

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.

0
votes

The decompose() function from the stats R package decomposes given time series into trend, seasonal component and reminder part. The seasonal component is a strictly periodical time series, and the period's length equals to the frequency of the time series. For example, if you set frequency = m, the decompose() function build decomposition which seasonal component will have period m. The decompose() function works if m is integer, m > 1, and length of the time series is greater or equal to 2m. The help page ?decompose notes that the time series should "covers an integer number of complete periods" in order the function works well. So it may be better if the series length is multiple of m.

There are no clear periodicity in your data. May be this discussion will be useful for you, because it contains Rob Hyndman's R script to reveal periodicity in a series.

0
votes

If you have data on daily basis then frequency is 365 for 365 days for a year as it contains 365 entries for a year as definition of frequency said it.

when you try to decompose using:

ts_0615391206_components <- decompose(ts_0615391206)

You are getting the error:

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

Because it takes at least two time series i.e. two years data to train the model otherwise it would throw an error