繁体   English   中英

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

[英]How to run Standard Normal Homogeneity Test for a time series data

我有近 40 个站点和 36 年的可变风的时间序列数据(样本数据)(样本截图中的详细信息)。

我需要根据建议对此数据运行标准正态同质性检验和佩蒂特检验。 它们是否在 python 中可用?

我在 python 文档和包中找不到上述测试的任何代码。

我需要一些帮助来了解是否有任何 package 持有这些测试。

R中有代码如下:

snht(data, period, robust = F, time = NULL, scaled = TRUE, rmSeasonalPeriod = Inf, ...)

但是,到目前为止没有结果......只有错误。

关于 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM