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 onlyalphais fitted. - If
xmin < 0, the optimal cutoff is found by minimising the Kolmogorov–Smirnov statistic. - If
force_continuousisfalseand every sample is an integer, a discrete model is fitted; otherwise a continuous one. Settingforce_continuous = truealways fits the continuous model.
The p-value is not computed (matching igraph’s default).
§Errors
InvalidArgumentifdatais empty, if a fixedxminis out of range (<= 0continuous,< 1discrete), or if no sample reachesxmin.
§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);