0


时间序列平稳性的双重假设检验:KPSS与ADF方法比较研究

在进行时间序列分析之前,确定序列的平稳性是一个关键步骤。平稳性指的是时间序列的统计特性(如均值和方差)在时间维度上保持不变。本文将详细介绍如何运用 KPSS 检验Dickey-Fuller 检验来验证序列的平稳性。这两种检验方法基于不同的统计假设:KPSS 检验的原假设是数据非平稳,而 Dickey-Fuller 检验则假设数据平稳。

时间序列平稳性的基本概念

时间序列的平稳性主要体现在三个方面:

  1. 均值稳定性:序列的期望值在时间维度上保持恒定
  2. 方差稳定性:数据波动范围保持相对稳定
  3. 无周期性:数据不存在明显的周期性波动或循环模式

平稳性是许多时间序列模型(如 ARIMA)的基本假设条件,对模型的有效性具有重要影响。

以下我们将通过构造平稳序列和非平稳序列来演示这两种检验方法的应用。

  1. importnumpyasnp
  2. importpandasaspd
  3. importmatplotlib.pyplotasplt
  4. fromstatsmodels.tsa.stattoolsimportadfuller, kpss
  5. # 构造平稳时间序列(白噪声过程)
  6. np.random.seed(42)
  7. stationary_series=np.random.normal(loc=0, scale=1, size=500)
  8. # 构造非平稳时间序列(随机游走过程)
  9. non_stationary_series=np.cumsum(np.random.normal(loc=0, scale=1, size=500))
  10. # 创建数据框用于后续分析
  11. data=pd.DataFrame({
  12. "Stationary": stationary_series,
  13. "Non-Stationary": non_stationary_series
  14. })
  15. plt.figure(figsize=(12, 6))
  16. plt.plot(data['Stationary'], label='Stationary Series')
  17. plt.plot(data['Non-Stationary'], label='Non-Stationary Series')
  18. plt.title('Stationary vs Non-Stationary Time Series')
  19. plt.xlabel('Time')
  20. plt.ylabel('Value')
  21. plt.legend()
  22. plt.grid()
  23. plt.savefig('stationary_vs_non_stationary.png')
  24. plt.show()

![]

  1. defkpss_test(series):
  2. statistic, p_value, _, critical_values=kpss(series, regression='c')
  3. print("KPSS Test:")
  4. print(f"Statistic: {statistic:.4f}")
  5. print(f"P-Value: {p_value:.4f}")
  6. print("Critical Values:")
  7. forkey, valueincritical_values.items():
  8. print(f"{key}: {value:.4f}")
  9. print(f"Conclusion: {'Stationary'ifp_value>0.05else'Non-Stationary'}\n")
  10. defadf_test(series):
  11. statistic, p_value, _, _, critical_values, _=adfuller(series)
  12. print("Dickey-Fuller Test:")
  13. print(f"Statistic: {statistic:.4f}")
  14. print(f"P-Value: {p_value:.4f}")
  15. print("Critical Values:")
  16. forkey, valueincritical_values.items():
  17. print(f"{key}: {value:.4f}")
  18. print(f"Conclusion: {'Stationary'ifp_value<0.05else'Non-Stationary'}\n")
  19. print("Testing the Stationary Series:\n")
  20. kpss_test(data['Stationary'])
  21. adf_test(data['Stationary'])
  22. print("Testing the Non-Stationary Series:\n")
  23. kpss_test(data['Non-Stationary'])
  24. adf_test(data['Non-Stationary'])

平稳序列检验结果分析

  • KPSS 检验结果显示 p 值大于显著性水平 0.05,未能拒绝序列平稳的原假设
  • Dickey-Fuller 检验的 p 值小于 0.05,拒绝序列存在单位根的原假设,证实序列平稳性

非平稳序列检验结果分析

  • KPSS 检验的 p 值小于 0.05,拒绝平稳性假设,表明序列非平稳
  • Dickey-Fuller 检验的 p 值大于 0.05,未能拒绝单位根假设,同样证实序列非平稳性

总结

时间序列的平稳性检验是建模过程中的重要环节。KPSS 和 Dickey-Fuller 检验提供了两种互补的统计方法,可以帮助研究者准确评估序列的平稳性特征,并为后续的数据转换(如差分处理)提供依据。

  • KPSS 检验适用于验证时间序列是否围绕确定性趋势呈现平稳特性
  • Dickey-Fuller 检验主要用于检验序列是否存在单位根,尤其适用于 ARIMA 建模前的平稳性验证

由于这两种检验方法基于不同的统计假设,在实际应用中通常建议同时使用两种方法进行交叉验证,以获得更可靠的结论。

“时间序列平稳性的双重假设检验:KPSS与ADF方法比较研究”的评论:

还没有评论