Setting pareto distribution with (python) Scipy

I have a dataset that I know has a Pareto distribution. Can someone tell me how to install this dataset in Scipy? I got the code below, but I have no idea what is being returned to me (a, b, c). Also, after getting a, b, c, how do I calculate the variance using them?

import scipy.stats as ss import scipy as sp a,b,c=ss.pareto.fit(data) 
+7
python scipy distribution
source share
2 answers

Here's a quick-written version, taking some clues from the help page that Rupert gave. This is currently done in scipy and statsmodels and requires MLE with some fixed or frozen parameters that are only available in boot versions. There are no standard errors in parameter estimates or other statistical data yet.

 '''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) 
+3
source share

Be very careful in choosing laws of power! Many registered power laws do not really comply with the force law. See Clauset et al for all details (also on arxiv if you do not have access to the magazine). They have a companion site in an article that now references the Python implementation. I don't know if he uses Scipy because I used my implementation of R when I last used it.

+1
source share

All Articles