This blog captures an error encountered while using “decompose” function in R on a ts (Time Series) object. The reason for error and fix are described.

**Error message:**

Error in decompose(Train.Arrival.a.ts) :

time series has no or less than 2 periods

**Reason:**

This error came up when I tried to use decompose function on train arrival times captured once a day over five months.

R line of code that gave error is

> Train.Arrival.a.decom = decompose(Train.Arrival.a.ts)

The possible reasons that I could gather from reading about this error are

1) The “frequency” or “deltat” parameter is incorrectly defined

2) Data is not of sufficient length to cover at least two seasonal cycles

The dataset had 1 observation per day and the intention was to interpret the data in daily periodicity. So, the frequency was set to 1 which looked logically correct. There were a total of 143 observations for a particular location.

I tried duplicating the available 143 rows to get 286 days of data. This time the decompose function worked fine as the pattern was forced to repeat twice and there is a seasonality cycle to detect.

**Fix:**

As the error message clearly says, there was no seasonal pattern in the data repeating at least two times that was causing the error. Also, there was not particular underlying trend that I could see from the plot.

I resorted to HoltWinters function and set beta = FALSE & gamma = FALSE to indicate absence of trend & seasonality respectively.

> Arrival.Forecasts = HoltWinters(Train.Arrival.a.ts,beta = FALSE,
gamma = FALSE)

This approach worked fine and I was able to come up with the forecasts for upcoming periods using HoltWinters simple exponential smoothing method.

### Like this:

Like Loading...

*Related*