用于KS测试的非标准分布变量?

时间:2016-08-24 20:30:34

标签: python python-2.7 scipy normal-distribution kolmogorov-smirnov

你可以在scipy.stats中使用kstest作为非标准分布函数(即改变学生的DOF,或改变Cauchy的伽玛)?我的最终目标是为我的分布拟合找到最大p值和相应参数,但这不是问题。

修改

"

scipy.stat的柯西pdf是:

cauchy.pdf(x) = 1 / (pi * (1 + x**2))

其中,x_0 = 0表示位置参数和gamma Y = 1。我实际上需要它看起来像这样

cauchy.pdf(x, x_0, Y) = Y**2 / [(Y * pi) * ((x - x_0)**2 + Y**2)]

"

Q1)学生们至少可以像

那样使用
stuff = []
for dof in xrange(0,100):
    d, p, dof = scipy.stats.kstest(data, "t", args = (dof, ))
    stuff.append(np.hstack((d, p, dof)))

因为它似乎可以选择改变参数吗?

Q2)如果您需要完整的正态分布方程(需要改变sigma)和Cauchy,如上所述(需要改变伽玛),你会怎么做? 编辑:不是搜索scipy.stats非标准发行版,实际上是否有可能将我写入kstest的函数提供给p值' s?

非常感谢

1 个答案:

答案 0 :(得分:1)

看起来你真正想做的是参数估计。以这种方式使用KT测试并不是它的真正含义。您应该使用corresponding distributiondisableVerification()方法。

.fit

现在快速查看文档:

>>> import numpy as np, scipy.stats as stats
>>> arr = stats.norm.rvs(loc=10, scale=3, size=10) # generate 10 random samples from a normal distribution
>>> arr
array([ 11.54239861,  15.76348509,  12.65427353,  13.32551871,
        10.5756376 ,   7.98128118,  14.39058752,  15.08548683,
         9.21976924,  13.1020294 ])
>>> stats.norm.fit(arr)
(12.364046769964004, 2.3998164726918607)
>>> stats.cauchy.fit(arr)
(12.921113834451496, 1.5012714431045815)

所以,让我们说我想让其中一个参数保持不变,你可以很容易地做到:

>>> help(cauchy.fit)

Help on method fit in module scipy.stats._distn_infrastructure:

fit(data, *args, **kwds) method of scipy.stats._continuous_distns.cauchy_gen instance
    Return MLEs for shape, location, and scale parameters from data.

    MLE stands for Maximum Likelihood Estimate.  Starting estimates for
    the fit are given by input arguments; for any arguments not provided
    with starting estimates, ``self._fitstart(data)`` is called to generate
    such.

    One can hold some parameters fixed to specific values by passing in
    keyword arguments ``f0``, ``f1``, ..., ``fn`` (for shape parameters)
    and ``floc`` and ``fscale`` (for location and scale parameters,
    respectively).

...

Returns
-------
shape, loc, scale : tuple of floats
    MLEs for any shape statistics, followed by those for location and
    scale.

Notes
-----
This fit is computed by maximizing a log-likelihood function, with
penalty applied for samples outside of range of the distribution. The
returned answer is not guaranteed to be the globally optimal MLE, it
may only be locally optimal, or the optimization may fail altogether.