算法手册/ 计量经济研究/ 季节性分解

季节性分解

计算公式

符号

符号含义
yt第 t 期的观测值
Tt趋势项,由居中移动平均得到
St季节项,同一相位在各周期上相同
Rt残差项,扣掉趋势与季节后的剩余
L季节周期长度(月度 12、季度 4)
m移动平均半窗:偶数 L 时 m = L/2;奇数 L 时 m = (L − 1)/2,窗口内等权
Sj一个周期内第 j 个相位的季节因子
FS、FT季节强度、趋势强度
n有效样本量

核心公式

公式 (1.1):加法与乘法分解
\[ y_t=T_t+S_t+R_t,\qquad y_t=T_t\times S_t\times R_t \]
公式 (1.2):居中移动平均趋势(L 为偶数)
\[ T_t=\frac{1}{2L}\left(y_{t-m}+y_{t+m}\right)+\frac{1}{L}\sum_{j=-(m-1)}^{m-1}y_{t+j},\qquad m=\frac{L}{2} \]
公式 (1.3):季节因子与中心化
\[ \bar S_j=\frac{1}{n_j}\sum_{k}\left(y_{j+kL}-T_{j+kL}\right),\qquad S_j=\bar S_j-\frac{1}{L}\sum_{l=1}^{L}\bar S_l \]
公式 (1.4):乘法模型的季节因子
\[ \bar S_j=\frac{1}{n_j}\sum_{k}\frac{y_{j+kL}}{T_{j+kL}},\qquad S_j=\frac{\bar S_j}{\frac{1}{L}\sum_{l=1}^{L}\bar S_l} \]
公式 (1.5):残差与强度指标
\[ R_t=y_t-T_t-S_t,\qquad F_S=\max\left(0,1-\frac{\operatorname{Var}(R)}{\operatorname{Var}(R+S)}\right),\qquad F_T=\max\left(0,1-\frac{\operatorname{Var}(R)}{\operatorname{Var}(R+T)}\right) \]

参考文献

  1. Hyndman, R. J., & Athanasopoulos, G. (2021). Forecasting: Principles and Practice (3rd ed.). OTexts.
  2. Cleveland, R. B., Cleveland, W. S., McRae, J. E., & Terpenning, I. (1990). STL: A seasonal-trend decomposition procedure based on loess. Journal of Official Statistics, 6(1), 3–73.
  3. Makridakis, S., Wheelwright, S. C., & Hyndman, R. J. (1998). Forecasting: Methods and Applications (3rd ed.). Wiley.

算法参数

参数取值默认影响
季节周期长度 整数,2 至 n/2 — 月度填 12、季度填 4;必填,且样本至少覆盖 2 个完整周期。
分解模型 加法 / 乘法 加法 加法按 y = T + S + R,乘法按 y = T × S × R。

验证报告

数据与 R 包

数据文件 season_decompose.csv
样本与变量 N = 72;Time 1–72 的月度序列,Y 含线性趋势、周期 12 的季节项与随机残差
R 包 stats 4.6.2(R 基础包)

提示词

对 Y 做季节分解,加法模型,周期长度 12,按 Time 排序,不写回成分。

R 代码

d <- read.csv("season_decompose.csv")
y <- ts(d$Y, frequency = 12)
dec <- decompose(y, type = "additive")
trend <- as.numeric(dec$trend)
seasonal <- as.numeric(dec$seasonal)
resid <- as.numeric(dec$random)
pop_sd <- function(x) {
  x <- x[is.finite(x)]
  sqrt(mean((x - mean(x))^2))
}
f <- function(x) format(x, digits = 15)
ok <- is.finite(trend) & is.finite(resid)
cat("trend", f(trend[7]), f(trend[66]), "\n")
cat("seasonal", paste(f(dec$figure), collapse = " "), "\n")
cat("season sd", f(pop_sd(seasonal)), "resid sd", f(pop_sd(resid)), "\n")
cat("amplitude", f(max(dec$figure) - min(dec$figure)), "mean", f(mean(y)), "\n")
cat("strength", f(max(0, 1 - var(resid[ok]) / var((resid + seasonal)[ok]))),
    f(max(0, 1 - var(resid[ok]) / var((resid + trend)[ok]))), "\n")

对比结果

指标SPSSAUR差值
季节周期12120
趋势起点(第 7 期)104.0076595160104.00765951601.2e−11
趋势终点(第 66 期)150.7904013076150.79040130768.01e−12
季节强度0.94198937750.94198937752.58e−11
趋势强度0.98857029900.98857029902.13e−11
季节项标准差5.89348558405.89348558401.18e−12
残差标准差1.46252394631.46252394631.51e−11
季节振幅17.909862999717.90986299975e−12
第 1 相位季节因子−7.8814324115−7.88143241151.42e−11
原始值均值127.5436646794127.54366467941.4e−11

结论:趋势、季节、残差三组统计量、季节强度与趋势强度均与 R 的季节分解结果一致到 10 位小数。两边都用窗口长 12 的居中移动平均,首尾各 6 期没有趋势/残差值是分解的端点效应;季节项按相位平均后再中心化,加法口径每个完整周期之和为 0(最大 8.95e−16)。强度按 Hyndman 的 max(0, 1 − Var(R)/Var(R+成分))、总体方差计算;换乘法模型或改 period 会改变数值,但分解口径不变。

操作手册 问题反馈

引用SPSSAU. 季节性分解:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/econometrics/season_decompose.html.