Fortranner
Fortranner

Reputation: 2605

R seasonal decomposition

I simulate a time series with periodic and linear components and try to use the R stl function to analyze it

n = 1000
x = ts(0.1*rnorm(n) + sin(6*pi*(1:n)/n) + (1:n)/n,frequency=n)
plot(x)
stl(x,"per")

but get a message

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

How do I use stl on the simulated time series?

Upvotes: 1

Views: 203

Answers (1)

jaimedash
jaimedash

Reputation: 2743

There must be more than 2 periods, so frequency must be less than n/2

n = 1000
x = ts(0.1*rnorm(n) + sin(6*pi*(1:n)/n) + (1:n)/n,
       frequency=n/2.1)

plot(x)
stl(x,"per")

Upvotes: 3

Related Questions