PowerLaws.jl
Documentation for PowerLaws.jl
PowerLaws.DistributionComparison
— TypeDistributionComparison
Fields
- data: array which according which should be distributions compared
- loglikelihoodratio: log likelihood ratio of data
- sig_level: sigma level
- xmin: smallest element which was used for comparing distributions
- Vteststat: Vuong test statistic
- Vpval: p-value from Vuong test
- Vpreffdistr: preffered distibution according to Vuong test
- C_b: Clarke test b value - sum of possitive values in log likehood ratio
- Cpval: p-value from Clarke test
- Cpreffdistr: preffered distibution according to Clarke test
PowerLaws.DistributionComparison
— MethodDistributionComparison
This function calculate Vuong test and Clarke test for non nested distributions. This is necessary since it is possible to fit power law distribution to any data set. Function was implemented according to this Non nested model selection for spatial count regression models with application to health insurance.
Arguments
d1
: First distribution to be compared.d2
: Second distribution to be compared.data
: Data to be compared.sig_level
: Significance level. Default is0.05
.
Returns
DistributionComparison
: Struct containing all necessary information about comparison.
PowerLaws.array_bins
— Methodarray_bins(arr::AbstractArray{T})::Dict{T,Int64} where {T <: Real}
Create a dictionary from a sorted array arr
where the keys are the unique elements and the values are the indices at which these elements first appear in the array.
PowerLaws.bootstrap
— Methodbootstrap
Bootstrap method for estimating the parameters of a power law distribution. To quantify the uncertainty in our estimate for xmin you can use bootstrap method. More information can be found in this document Power-law distributions in empirical data.
Arguments
data::AbstractArray
: Data to be tested.d::UnivariateDistribution
: Distribution to be tested (ContinuousPowerLaw
orDiscretePowerLaw
).no_of_sims::Int64
: Number of simulations. Default is10
.xmins::AbstractArray
: Array of xmins to be tested, default isdata
.xmax::Int64
: Maximum value of data to be considered. Default is1e5
.seed::Int64
: Seed for random number generator. Default is0
.
Returns
statistic::Array{Tuple{UnivariateDistribution, Float64}}
: Array of tuples containing the distribution and the Kolmogorov-Smirnov distance between the data and the distribution.
PowerLaws.bootstrap_p
— Methodbootstrap_p
Performs a bootstrapping hypothesis test to determine whether a power law distribution is plausible. Inspired by R poweRlaw documentation.
Arguments
data::AbstractArray
: Data to be tested.d::UnivariateDistribution
: Distribution to be tested (ContinuousPowerLaw
orDiscretePowerLaw
).no_of_sims::Int64
: Number of simulations. Default is10
.xmins::AbstractArray
: Array of xmins to be tested, default isdata
.xmax::Int64
: Maximum value of data to be considered. Default is1e5
.seed::Int64
: Seed for random number generator. Default is0
.
Returns
statistic::Array{Tuple{UnivariateDistribution, Float64}}
: Array of tuples containing the distribution and the Kolmogorov-Smirnov distance between the data and the distribution.P::Float64
: p-value of the hypothesis test.
PowerLaws.estimate_parameters
— Methodestimate_parameters
Estimate x_min
and α
for a given data set with respect to the Kolmogorov-Smirnov test.
Parameters
data::AbstractArray
: Array of data which should be fit to a distribution.distribution::Type
: Distribution type, i.e.ContinuousPowerLaw
orDiscretePowerLaw
.xmins::AbstractArray
: If not specified, all unique values indata
are taken as possiblex_min
s. If specified, only values inxmins
are considered when finding the bestx_min
.xmax::Int64
: Maximum value considered in calculations. Values abovexmax
are not considered in, for example, calculating the Kolmogorov-Smirnov test.
Returns
best_fit::distribution
: A distribution of the typedistribution
fitted to the given parameters.KS::Float64
: The Kolmogorov-Smirnov distance between the data and the fitted distribution.
PowerLaws.kolmogorov_smirnov_test
— Functionkolmogorovsmirnovtest
Calculate Kolmogorov Smirnov test on given data and distribution.
Arguments
dat::AbstractArray
: Data to be tested.d::UnivariateDistribution
: Distribution to be tested (ContinuousPowerLaw
orDiscretePowerLaw
).xmin::Number
: Minimum value of data to be considered.xmax::Int64
: Maximum value of data to be considered. Default is1e5
.
Returns
KS::Float64
: Kolmogorov-Smirnov distance between the data and the distribution. It is the maximum absolute difference between the empirical and theoretical cumulative distribution functions (`cdf