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

标签 python statistics normalization

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

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

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

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

R中有如下代码:

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

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

最佳答案

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

关于python - 如何对时间序列数据运行标准正态同质性检验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58537876/

相关文章:

python - 在 jupyter 笔记本上显示 plotly

python - 将列名分配给 Pandas 系列

r - 用 NA 值计算卡方

python - 使用 statsmodels 进行最大似然估计会使事情变得过于复杂?希望大家推荐

unicode - 案例折叠后需要归一化

scikit-learn - 使用 Sklearn 的 MinMaxScaler 按行缩放

python - 有没有办法使用他们的 API 搜索 edx 类(class)?

python - Celery 将命令行参数传递给 Task

python - 如何在 python 中对两个 np.array 执行两个样本不等大小的 t 检验?

python - 按百分比标准化滚动窗口(pandas)