簡體   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