如何对时间序列数据运行标准正态同质性检验

3
我有一组时间序列数据(示例数据),涉及近40个站点和36年的风速变量(详细信息请参见示例截图)。
根据建议,我需要对这些数据运行标准正态同质性检验和Pettitt检验。它们在Python中是否可用?
我在Python文档和包中找不到任何关于上述测试的代码。
我需要帮助了解是否有包含这些测试的软件包。
以下是R语言的代码:
snht(data, period, robust = F, time = NULL, scaled = TRUE, rmSeasonalPeriod = Inf, ...)

然而,到目前为止没有结果...只有错误。
1个回答

2
关于Pettitt测试,我发现了这个Python实现:链接
我认为有一个小错误:第19行的t+1实际上应该是t
此外,我还开发了一个更快、矢量化的实现方法:
import numpy as np

def pettitt_test(X):
    """
    Pettitt test calculated following Pettitt (1979): https://www.jstor.org/stable/2346729?seq=4#metadata_info_tab_contents
    """

    T = len(X)
    U = []
    for t in range(T): # t is used to split X into two subseries
        X_stack = np.zeros((t, len(X[t:]) + 1), dtype=int)
        X_stack[:,0] = X[:t] # first column is each element of the first subseries
        X_stack[:,1:] = X[t:] # all rows after the first element are the second subseries
        U.append(np.sign(X_stack[:,0] - X_stack[:,1:].transpose()).sum()) # sign test between each element of the first subseries and all elements of the second subseries, summed.

    tau = np.argmax(np.abs(U)) # location of change (first data point of second sub-series)
    K = np.max(np.abs(U))
    p = 2 * np.exp(-6 * K**2 / (T**3 + T**2))
        
    return (tau, p)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接