问题
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.
Install Gnu Scientific Library (GSL)
In Debian:
apt-get install libgl2
- Download powerlaw python library code from github.
unpack and build
exponential-integral.tgz
file located attesting/pli-R-v0.0.3-2007-07-25/
folder of the previously downloaded library.tar xzf exponential-integral.tgz cd exponential-integral make
Move
exp_int
file to an executable path, namedyourexecutablepath
from here on.mv exp_int yourexecutablepath
Modify
exp_int_function_filename
variable from powerexp.R file with the full path to exp_int executable, i.e.yourexecutablepath/exp_int
.eval
exp.R
,pareto.R
andpowerexp.R
R source code to include all the needed functions.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