【问题标题】:How to run Standard Normal Homogeneity Test for a time series data如何对时间序列数据运行标准正态同质性检验
【发布时间】:2020-02-20 14:06:15
【问题描述】:

我有一个时间序列数据 (sample data),用于近 40 个站点和 36 年的变风(示例截图中的详细信息)。

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

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

我需要一些帮助来了解是否有任何包含这些测试的包。

R中有如下代码:

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

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

【问题讨论】:

    标签: python statistics normalization


    【解决方案1】:

    关于 Pettitt 测试,我找到了this 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)
    

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 2013-10-15
      • 2013-02-03
      • 2019-04-04
      • 1970-01-01
      • 2012-01-02
      • 2020-08-11
      • 1970-01-01
      • 2018-07-07
      相关资源
      最近更新 更多