时间序列显然是周期性的,但季节性分解在 R 中不起作用

机器算法验证 r 时间序列 季节性
2022-03-23 08:34:05

我的时间序列显然是周期性的,但是使用 stl() 的季节性分解在 R 中不起作用:

a <- c(6.7, 20.3, 23.5,  7.9,  3.3,  2.0,  2.5,  2.9,  2.3,  5.0, 15.0, 20.1, 27.0, 28.2, 18.3,  7.8,  1.6,  0.8,  1.3,  1.2,  0.6,
1.6,  4.9, 24.2, 28.8, 23.6, 18.6,  5.3,  1.8,  0.4,  0.5,  0.2,  0.1,  0.3,  3.5, 17.6, 26.1, 22.7, 18.2,  7.2,  2.1,  1.0,
1.1,  1.4,  0.7,  3.2,  7.6, 22.3, 30.4, 26.5, 23.2,  8.6,  4.3,  1.5,  1.7,  2.4,  0.9,  3.0,  8.0, 21.9, 25.9, 25.6, 25.2,
13.1,  5.4,  2.2,  2.8,  2.7,  1.9,  5.1, 12.4, 28.4, 27.8, 22.2, 21.1, 13.6,  6.1,  4.0,  3.7,  4.5,  3.6,  6.3, 11.1, 25.0,
31.1, 24.5, 22.1, 10.9,  5.2,  2.6,  4.4,  4.1,  3.1,  7.0, 17.3, 25.5, 30.1)
a.ts <- as.ts(a, frequency=12, begin=c(1980,1))
stl(a.ts,s.window = "periodic")

输出:

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

阴谋

我的主要目标是消除时间序列的季节性。

1个回答

不要使用as.ts(). 这样做(注意:参数被称为start,而不是begin):

a.ts <- ts(a, frequency=12, start=c(1980,1))