Skip to main content

power_law_fit

Function power_law_fit 

Source
pub fn power_law_fit(
    data: &[f64],
    xmin: f64,
    force_continuous: bool,
) -> IgraphResult<PowerLawFitResult>
Expand description

Fit a power-law distribution to a sample of numbers.

Counterpart of igraph_power_law_fit(). P(X = x) is assumed proportional to x^(-alpha) for x >= xmin.

  • If xmin >= 0, that cutoff is fixed and only alpha is fitted.
  • If xmin < 0, the optimal cutoff is found by minimising the Kolmogorov–Smirnov statistic.
  • If force_continuous is false and every sample is an integer, a discrete model is fitted; otherwise a continuous one. Setting force_continuous = true always fits the continuous model.

The p-value is not computed (matching igraph’s default).

§Errors

  • InvalidArgument if data is empty, if a fixed xmin is out of range (<= 0 continuous, < 1 discrete), or if no sample reaches xmin.

§Examples

use rust_igraph::power_law_fit;

// A continuous power-law tail; fit alpha with a fixed cutoff.
let data = vec![1.0, 2.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0, 34.0, 55.0];
let fit = power_law_fit(&data, 1.0, true).unwrap();
assert!(fit.continuous);
assert!(fit.alpha > 1.0);
assert_eq!(fit.xmin, 1.0);