泊松过程检验

2024-05-12 14:37:04 发布

您现在位置:Python中文网/ 问答频道 /正文

{我想从一些事件的齐次检验中得到的。因此,对于固定数量的事件,时间应该看起来像是在适当范围内统一分布的排序版本。在http://docs.scipy.org/doc/scipy-0.7.x/reference/generated/scipy.stats.kstest.html上有一个Kolmogorov-Smirnov测试的实现,但是我不知道如何在这里使用它scipy.stats公司似乎不知道泊松过程。在

作为一个简单的例子,对于任何这样的测试,这个样本数据应该给出一个很高的p值。在

import random
nopoints = 100
max = 1000

points = sorted([random.randint(0,max) for j in xrange(nopoints)])

我怎样才能对这个问题做一个合理的测试呢?在

从www.stat.wmich.edu/wang/667/classnotes/pp/pp.pdf我明白了

““ 注6.3(检验泊松)上述定理也可用于检验假设 一个给定的计数过程是一个泊松过程。这可以通过观察一个固定时间t的过程来实现。如果在这个时间段内我们观察到n个事件,并且如果这个过程是Poisson,那么无序的发生时间将独立且均匀地分布在(0,t)上。因此,我们可以通过检验n个发生时间来自统一(0,t)总体的假设来检验这个过程是否是泊松的。这可以通过标准的统计程序来完成,如Kolmogorov-Smirov试验。”


Tags: 版本http数量排序过程stats时间事件
3条回答

当确定两个分布是否不同时,KS test只是它们之间最大的差别:

enter image description here

这很简单,可以自己计算。下面的程序计算两个具有不同参数集的泊松过程的KS统计量:

import numpy as np

N = 10**6
X  = np.random.poisson(10, size=N)
X2 = np.random.poisson(7, size=N)

bins = np.arange(0, 30,1)
H1,_ = np.histogram(X , bins=bins, normed=True)
H2,_ = np.histogram(X2, bins=bins, normed=True)

D = np.abs(H1-H2)

idx = np.argmax(D)
KS = D[idx]

# Plot the results
import pylab as plt
plt.plot(H1, lw=2,label="$F_1$")
plt.plot(H2, lw=2,label="$F_2$")
text = r"KS statistic, $\sup_x |F_1(x) - F_2(x)| = {KS:.4f}$"
plt.plot(D, ' k', label=text.format(KS=KS),alpha=.8)
plt.scatter([bins[idx],],[D[idx],],s=200,lw=0,alpha=.8,color='k')
plt.axis('tight')
plt.legend()

enter image description here

问题是,正如您链接到的文档所建议的那样:"The KS test is only valid for continuous distributions."而泊松分布是离散的。在

我建议你用这个链接中的例子: http://nbviewer.ipython.org/urls/raw.github.com/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/master/Chapter1_Introduction/Chapter1_Introduction.ipynb (查找“示例:从短信数据推断行为”)

在该链接中,他们检查特定数据集的适当lambda(s)假设根据poisson过程分布。在

警告:写得很快,有些细节无法验证

指数自由度的chisquare检验的合适估计量是什么

根据课堂讲稿

三种测试都没有否定同质性的含义。 说明如何使用的kstest和chisquare testscipy.stats公司在

# -*- coding: utf-8 -*-
"""Tests for homogeneity of Poissson Process

Created on Tue Sep 17 13:50:25 2013

Author: Josef Perktold
"""

import numpy as np
from scipy import stats

# create an example dataset
nobs = 100
times_ia = stats.expon.rvs(size=nobs) # inter-arrival times
times_a = np.cumsum(times_ia) # arrival times
t_total = times_a.max()

# not used
#times_as = np.sorted(times_a)
#times_ia = np.diff(times_as)

bin_limits = np.array([ 0. ,  0.5,  1. ,  1.5,  2. ,  np.inf])
nfreq_ia, bins_ia = np.histogram(times_ia, bin_limits)


# implication: arrival times are uniform for fixed interval
# using times.max() means we don't really have a fixed interval
print stats.kstest(times_a, stats.uniform(0, t_total).cdf)

# implication: inter-arrival times are exponential
lambd = nobs * 1. / t_total
scale = 1. / lambd

expected_ia = np.diff(stats.expon.cdf(bin_limits, scale=scale)) * nobs
print stats.chisquare(nfreq_ia, expected_ia, ddof=1)

# implication: given total number of events, distribution of times is uniform
# binned version
n_mean_bin = 10
n_bins_a = nobs // 10
bin_limits_a = np.linspace(0, t_total+1e-7, n_bins_a + 1)
nfreq_a, bin_limits_a = np.histogram(times_a, bin_limits_a)
# expect uniform distributed over every subinterval
expected_a = np.ones(n_bins_a) / n_bins_a * nobs
print stats.chisquare(nfreq_a, expected_a, ddof=1)

相关问题 更多 >