다음은 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)
python 구현 (http://code.google.com/p/agpy/wiki/PowerLaw)에는 두 가지 버전이 있습니다. 하나는 numpy에 의존하고, 하나는 그렇지 않습니다. (내가 썼어) – keflavich