user3642360
user3642360

Reputation: 792

ERROR in R: decompose(y) : time series has no or less than 2 periods

I have a time series data of daily transactions, starting from 2017-06-28 till 2018-11-26. The data looks like this:

enter image description here

I am interested to use decompose() or stl() function in R. But I am getting

error:
decompose(y) : time series has no or less than 2 periods

when I am trying to use decompose() and

Error in stl(y, "periodic") : 
  series is not periodic or has less than two periods

when I am trying to use stl().

I have understood that I have to specify the period, but I am not able to understand what should be the period in my case? I have tried with the following toy example:

dat <- cumsum(rnorm(51.7*10))
y <- ts(dat, frequency = 517)
plot.ts(y)
stl(y, "periodic")

But I couldn't succeed. Any help will be highly appreciated.

Upvotes: 2

Views: 4980

Answers (1)

NRLP
NRLP

Reputation: 578

The frequency parameter reflects the number of observations before the seasonal pattern repeats. As your data is daily, you may want to set frequency equal to 7 or 365.25 (depending on your business seasonality).

Of course, the larger the business seasonality, the more data you need (i.e. more than 2 periods) in order to decompose your time series. In your case, you set the frequency to 517, but have data available for less than two periods. Thus, the seasonal decomposition cannot happen.

For more info, please see: Rob Hyndman's Forecasting Principles and Practice book

Upvotes: 2

Related Questions