Replicating power law distribution

Hi,

I am trying to generate a power law degree distribution using barabasi_albert from Graphs.jl. I am having trouble replicating the figure 4 on page 7 of this resource. Please forgive me in advance if I am doing something wrong, or have a conceptual misunderstanding. My understanding is that the slope of the degree distribution should be close to -3 in log space. In the example provided in the link, the slope is -2.79. However, I obtain -2.12. Can someone please provide some guidance?

Thank you!

Code
using CurveFit
using Graphs 
using Plots

graph = barabasi_albert(100_000, 3, 3; is_directed = true)

degrees = degree(graph)
unique_degrees = unique(degrees)
degree_probs = map(d -> mean(d .== degrees), unique_degrees)

log_log_plot = Plots.scatter(
    unique_degrees,
    degree_probs,
    xaxis = (:log10, font(8)),
    yaxis = (:log10, font(8)),
    grid = false,
    leg = false,
    markersize = 2.5,
    xlabel = "degree",
    ylabel = "probability",
)
fit = curve_fit(LinearFit, log10.(unique_degrees), log10.(degree_probs))
plot!(unique_degrees, 10 .^ fit.(log10.(unique_degrees)), color = :black)
plot!(1:1000, (1:1000).^(-3), color = :blue)

Estimating powerlaws via linear regression hardly ever works – see Power-law distributions in empirical data for details and proper ML based estimation algorithms. Unfortunately, there only seems to be an abandoned package in Julia …
In any case, here is a quick estimate on your data using formula (B.17) from the paper and an arbitrary x_{min}:

julia> xmin = 23
23

julia> x = degrees[degrees .> xmin];

julia> 1 + inv(mean(log.(x ./ (xmin - 1/2))))
2.810142626941318

which is already much closer to the analytic exponent.

2 Likes

Thanks for your help!

Indeed, I was wondering about the tail, which is flattened because the minimum empirical probability must be 1/n.

FWIW, using RobustModels.jl, one can obtain the following result:

2 Likes

Nice find. Thanks!

1 Like