简体   繁体   English

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

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

I have a timeseries data ( sample data ) for a variable wind for nearly 40 stations and 36 years (details in sample screenshot).我有近 40 个站点和 36 年的可变风的时间序列数据(样本数据)(样本截图中的详细信息)。

I need to run the Standard Normal Homogeneity Test and Pettitt's Test for this data as per recommendations.我需要根据建议对此数据运行标准正态同质性检验和佩蒂特检验。 Are they available in python?它们是否在 python 中可用?

I couldn't find any code for the mentioned tests in python documentations and packages.我在 python 文档和包中找不到上述测试的任何代码。

I need some help here to know if there is any package holding these tests.我需要一些帮助来了解是否有任何 package 持有这些测试。

There are codes in R as follows: R中有代码如下:

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

However, no results so far... only errors.但是,到目前为止没有结果......只有错误。

Regarding the Pettitt test, I found this python implementation.关于 Pettitt 测试,我发现 了这个python 实现。

I believe there is a small typo: the t+1 on line 19 should actually just be t .我相信有一个小错字:第 19 行的t+1实际上应该只是t

I also have developed a faster, vectorised implementation::我还开发了一个更快的矢量化实现:

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