# fit_power_law

##### Fitting a power-law distribution function to discrete data

`fit_power_law`

fits a power-law distribution to a data set.

- Keywords
- graphs

##### Usage

```
fit_power_law(x, xmin = NULL, start = 2, force.continuous = FALSE,
implementation = c("plfit", "R.mle"), ...)
```

##### Arguments

- x
- The data to fit, a numeric vector. For implementation
the data must be integer values. For the`R.mle`

implementation non-integer values might be present and then a continuous power-law distr`plfit`

- xmin
- Numeric scalar, or
`NULL`

. The lower bound for fitting the power-law. If`NULL`

, the smallest value in`x`

will be used for the implementation, and its value will be automatically determ`R.mle`

- start
- Numeric scalar. The initial value of the exponent for the
minimizing function, for the
implementation. Ususally it is safe to leave this untouched.`R.mle`

- force.continuous
- Logical scalar. Whether to force a continuous
distribution for the
implementation, even if the sample vector contains integer values only (by chance). If this argument is false, igraph will assume a continuous distribut`plfit`

- implementation
- Character scalar. Which implementation to use. See details below.
- ...
- Additional arguments, passed to the maximum likelihood
optimizing function,
`mle`

, if the implementation is chosen. It is ignored by the`R.mle`

`plfit`

##### Details

This function fits a power-law distribution to a vector containing samples from a distribution (that is assumed to follow a power-law of course). In a power-law distribution, it is generally assumed that $P(X=x)$ is proportional to $x^{-alpha}$, where $x$ is a positive number and $\alpha$ is greater than 1. In many real-world cases, the power-law behaviour kicks in only above a threshold value $x_{min}$. The goal of this function is to determine $\alpha$ if $x_{min}$ is given, or to determine $x_{min}$ and the corresponding value of $\alpha$.

`fit_power_law`

provides two maximum likelihood implementations. If
the `implementation`

argument is `R.mle`

*not* to fit the $x_{min}$ argument, so use the
`plfit`

The `plfit`

##### Value

- Depends on the
`implementation`

argument. If it is , then an object with class`R.mle`

. It can be used to calculate confidence intervals and log-likelihood. See`mle`

`mle-class`

for details.If

`implementation`

is , then the result is a named list with entries:`plfit`

continuous Logical scalar, whether the fitted power-law distribution was continuous or discrete. alpha Numeric scalar, the exponent of the fitted power-law distribution. xmin Numeric scalar, the minimum value from which the power-law distribution was fitted. In other words, only the values larger than `xmin`

were used from the input vector.logLik Numeric scalar, the log-likelihood of the fitted parameters. KS.stat Numeric scalar, the test statistic of a Kolmogorov-Smirnov test that compares the fitted distribution with the input vector. Smaller scores denote better fit. KS.p Numeric scalar, the p-value of the Kolmogorov-Smirnov test. Small p-values (less than 0.05) indicate that the test rejected the hypothesis that the original data could have been drawn from the fitted power-law distribution.

##### References

Power laws, Pareto distributions and Zipf's law, M. E. J.
Newman, *Contemporary Physics*, 46, 323-351, 2005.

Aaron Clauset, Cosma R .Shalizi and Mark E.J. Newman: Power-law distributions in empirical data. SIAM Review 51(4):661-703, 2009.

##### See Also

##### Examples

```
# This should approximately yield the correct exponent 3
g <- barabasi.game(1000) # increase this number to have a better estimate
d <- degree(g, mode="in")
fit1 <- fit_power_law(d+1, 10)
fit2 <- fit_power_law(d+1, 10, implementation="R.mle")
fit1$alpha
stats4::coef(fit2)
fit1$logLik
stats4::logLik(fit2)
```

*Documentation reproduced from package igraph, version 1.0.0, License: GPL (>= 2)*