8

I'm experimenting with fitting a power law to empirical data using the powerlaw module. I have created the following data that follows a power law distribution of exponent 2:

x = range(1,1000)
y = []

for i in x:
    y.append(i**(-2))

I'm expecting the fitted power law to have an exponent of 2. However the resulting exponent deviates from the theoretical value a lot:

    fitted_pl = powerlaw.Fit(y)

    fitted_pl.alpha
    Out[115]: 1.4017584065981563

Could you please advise why this happens, or point out what I've done wrong here?

Thank you for your kind answer!

Moses Xu
  • 2,140
  • 4
  • 24
  • 35
  • 1
    When you write `y.append(x**(-2))`, I think you mean `y.append(i**(-2))` – Brionius Aug 11 '13 at 00:41
  • 1
    Are you maybe confusing regression of the line `y(x) = k x^(-a)` with fitting an exponent to values drawn from the *probability distribution* `p(x) ~ (a-1) x^(-a)`? [The k->a change is intentional.] The `powerlaw` module addresses the second question. – DSM Aug 11 '13 at 02:58
  • @DSM, you are absolutely right! I was confusing the two very different tasks. Thank you so much for pointing this out! – Moses Xu Aug 12 '13 at 06:31

1 Answers1

11

As @DSM pointed out, the powerlaw module deals with fitting an exponent to values drawn/generated from a power law distribution, rather than fitting a regression. To help people who might have similar confusions, below is how one should verify the exponent fitting:

## use a proper power law random number generator (or code your own) 
from networkx.utils import powerlaw_sequence
pl_sequence = powerlaw_sequence(1000,exponent=2.5)

fitted_pl = powerlaw.Fit(pl_sequence)

fitted_pl.alpha
Out[73]: 2.4709012785346314  ##close enough
Moses Xu
  • 2,140
  • 4
  • 24
  • 35