0
votes

I am studying Time Series with R. Using the stl() command I get the error

Error in stl(avatar_ts, s.window = "periodic") : series is not periodic or has less than two periods

Below is my code.

avatar_ts = ts(avatar_data$Gross, start = c(2009,12), frequency=365)
st_decompose_method = stl(avatar_ts, s.window="periodic")

If I change the frequency to 12 or 50, the stl() functions runs. However my dataset has daily observations from 2009-12-18 till 2010-11-18; a total 318 observation.

(Basically it is daily data but detected a few missing weeks since it is daily movie profit dataset)

How can I use the stl() function with frequency of 365 for the time series data?

1

1 Answers

0
votes

The unhelpful answer here is that you can use stl() on daily data if you have at least two years of observations. You define the s.window as "periodic" but since you have less than one year of data which is insufficient.

See the example with simulated data below.

First, with your number of observations:

x <-rnorm(318)
d <- ts(x, start = c(2009,12), frequency = 365)
st_decompose_method = stl(d, s.window="periodic")

This will give the error:

Error in stl(d, s.window = "periodic") : 
  series is not periodic or has less than two periods

Now with at least two years of data, so minimum of two periods:

x <-rnorm(731)
d <- ts(x, start = c(2009,12), frequency = 365)
st_decompose_method = stl(d, s.window="periodic")

Which will work.

Note by the way that your ts specification is incorrect as you don't provide the start day. To do this you could do the following:

days <- seq(as.Date("2009-12-18"), as.Date("2010-11-18"), by = "day")
avatar_ts = ts(avatar_data$Gross, 
               start = c(2009, as.numeric(format(days[1], "%j"))), 
               frequency=365)