用(python)Scipy拟合帕累托分布

ale*_*lex 8 python distribution scipy

我有一个我知道有Pareto分布的数据集.有人能指出我如何在Scipy中使用这个数据集吗?我得到了下面的代码来运行,但我不知道什么是返回给我(a,b,c).此外,在获得a,b,c后,如何使用它们计算方差?

import scipy.stats as ss 
import scipy as sp

a,b,c=ss.pareto.fit(data)
Run Code Online (Sandbox Code Playgroud)

Rup*_*ash 6

非常小心地拟合幂律!!许多报道的幂律实际上不符合幂律。见克劳塞特等人。有关所有详细信息(如果您无法访问该期刊,也可以在arxiv查看)。他们有一个文章的配套网站,现在链接到 Python 实现。不知道它是否使用 Scipy,因为我上次使用它时使用了他们的 R 实现。

  • python 实现 (http://code.google.com/p/agpy/wiki/PowerLaw) 包括两个版本;一个依赖于 numpy,一个不依赖。(我写的) (2认同)

Jos*_*sef 5

这是一个快速编写的版本,从 Rupert 提供的参考页面中获取了一些提示。这目前正在 scipy 和 statsmodels 中进行,并且需要具有一些固定或冻结参数的 MLE,这仅在主干版本中可用。目前还没有关于参数估计或其他结果统计的标准误差。

'''estimating pareto with 3 parameters (shape, loc, scale) with nested
minimization, MLE inside minimizing Kolmogorov-Smirnov statistic

running some examples looks good
Author: josef-pktd
'''

import numpy as np
from scipy import stats, optimize
#the following adds my frozen fit method to the distributions
#scipy trunk also has a fit method with some parameters fixed.
import scikits.statsmodels.sandbox.stats.distributions_patch

true = (0.5, 10, 1.)   # try different values
shape, loc, scale = true
rvs = stats.pareto.rvs(shape, loc=loc, scale=scale, size=1000)

rvsmin = rvs.min() #for starting value to fmin


def pareto_ks(loc, rvs):
    est = stats.pareto.fit_fr(rvs, 1., frozen=[np.nan, loc, np.nan])
    args = (est[0], loc, est[1])
    return stats.kstest(rvs,'pareto',args)[0]

locest = optimize.fmin(pareto_ks, rvsmin*0.7, (rvs,))
est = stats.pareto.fit_fr(rvs, 1., frozen=[np.nan, locest, np.nan])
args = (est[0], locest[0], est[1])
print 'estimate'
print args
print 'kstest'
print stats.kstest(rvs,'pareto',args)
print 'estimation error', args - np.array(true)
Run Code Online (Sandbox Code Playgroud)