Power Law Fit of cut-off distribution with the poweRlaw package

最后都变了- 提交于 2019-12-12 18:36:20

问题


I am currently trying to find a way to calculate a power-law fit for a cut-off distribution with MLE. The distribution looks as follows:

As you can see, I was able to fit the whole distribution (Power-law fit) and also the lower bound (exp-fit) separately. What I am failing to figure out, is how to fit the upper bound of the distribution (f.e. 8 < x < 100).

Is there any way to do this with the poweRlaw package or any other R package? What I am hoping for is something looking like this (note: it is just a random distribution):

Code (if necessary):

#Power-Law
library("poweRlaw")
xmin1 <- 8
xmin2 <- 100
plf0 <- displ$new(deg)
plf0$setXmin(xmin1)
plf0_pars <- estimate_pars(plf0)
plf0$setPars(plf0_pars)

#Exponential
exp1 <- disexp$new(deg)
exp1$setXmin(xmin2)
exp1_pars <- estimate_pars(exp1)
exp1$setPars(exp1_pars)
plot(plf0)
lines(plf0, col="green")
lines(exp1, col="red")

回答1:


You can't fit this type of model with the poweRlaw package (I'm the package author).

It's unlikely to be added to the package in the near package.




回答2:


Following solution provides R code that can be run with Python using rpy2.

It provides instructions based in the source code by powerlaw library, as suggested by the answer by Kelvin, mainly from: https://github.com/jeffalstott/powerlaw/blob/master/testing/pli-R-v0.0.3-2007-07-25/powerexp.R file.

  1. Install Gnu Scientific Library (GSL)

    In Debian: apt-get install libgl2

  2. Download powerlaw python library code from github.
  3. unpack and build exponential-integral.tgz file located at testing/pli-R-v0.0.3-2007-07-25/ folder of the previously downloaded library.

    tar xzf exponential-integral.tgz
    cd exponential-integral
    make
    
  4. Move exp_int file to an executable path, named yourexecutablepath from here on.

    mv exp_int yourexecutablepath

  5. Modify exp_int_function_filename variable from powerexp.R file with the full path to exp_int executable, i.e. yourexecutablepath/exp_int.

  6. eval exp.R, pareto.R and powerexp.R R source code to include all the needed functions.

  7. Fit your data to a powerlaw with exponential cut-off evaluating the following R call:

    data <- list(5, 3, ...)
    powerexp.fit(unlist(data))
    

The output of the last command provides several output values, among them exponent which gives the power law alpha value and rate which gives the exponential cut-off parameter.



来源:https://stackoverflow.com/questions/45119636/power-law-fit-of-cut-off-distribution-with-the-powerlaw-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!