pub struct PowerLawFit<'a> {
pub continuous: bool,
pub alpha: f64,
pub xmin: f64,
pub log_likelihood: f64,
pub ks_statistic: f64,
pub data: &'a [f64],
}Expand description
A power-law distribution fitted to a sample by power_law_fit (the
Rust counterpart of igraph_plfit_result_t).
The fitted model is P(X = x) ∝ x^(-alpha) for x >= xmin. The struct
borrows the fitted sample, which is needed to compute the
p-value of the fit.
Fields§
§continuous: boolWhether a continuous (true) or a discrete (false) power law was fitted.
alpha: f64The fitted exponent alpha (larger than 1 for a normalizable law).
xmin: f64The threshold above which the power-law behavior holds (given, or estimated by minimizing the Kolmogorov–Smirnov statistic).
log_likelihood: f64The log-likelihood of the fitted parameters (L in igraph).
ks_statistic: f64The Kolmogorov–Smirnov test statistic between the fitted
distribution and the sample (D in igraph); the smaller, the better.
data: &'a [f64]The sample the model was fitted to.
Implementations§
Source§impl PowerLawFit<'_>
impl PowerLawFit<'_>
Sourcepub fn p_value(&self, precision: f64) -> Result<f64>
pub fn p_value(&self, precision: f64) -> Result<f64>
Computes the p-value of the fit by a (slow) resampling procedure.
Many synthetic datasets are drawn: the part of the sample below xmin
is resampled from the data itself, the part above xmin from the
fitted power law. A power law is fitted to each of them, and the
p-value is the fraction of synthetic datasets whose Kolmogorov–Smirnov
statistic is larger than the observed one. Small p-values (e.g.
below 0.1) mean that the power-law hypothesis can be rejected.
The number of resampling rounds is 0.25 / precision²: a precision of
0.01 means 2500 rounds. Results depend on the thread’s default
random number generator (seed it with rng::seed);
if igraph was built with OpenMP, the rounds run in parallel and the
results are not reproducible unless OpenMP is limited to one thread.
Binds igraph_plfit_result_calculate_p_value.
The fields of the struct are public, so the model is checked before
calling igraph (whose resampling code crashes or loops forever on
some invalid models): it must have a non-empty, finite sample, a
finite alpha > 1 (degenerate fits with alpha = inf are rejected),
and a finite xmin, positive for a continuous law and in [1, 4e18)
for a discrete one. The samples of a discrete model must also be below
2^62.
Known upstream issue. For discrete models, plfit draws from the
fitted law with (long) floor(pow(1 - u, -1 / (alpha - 1)) * xmin),
relying on the conversion of too large values to a C long to “handle
overflow” (vendor/plfit/sampling.c). Such a conversion is undefined
behavior in C; on x86-64 it yields a negative number and the draw is
retried. This cannot be ruled out from Rust without constraining
alpha: it only happens for extremely heavy tails (alpha close to
1), which huge samples produce most readily, hence the 2^62 bound
above.
§Errors
ErrorKind::InvalidValue if
precision is not a positive number, is so small that the number of
rounds would not fit in a 64-bit integer (below about 2.5e-10), or
so large that there would be no round at all (above 0.5); if the
model is invalid (see above); and the errors of power_law_fit.
Trait Implementations§
Source§impl<'a> Clone for PowerLawFit<'a>
impl<'a> Clone for PowerLawFit<'a>
Source§fn clone(&self) -> PowerLawFit<'a>
fn clone(&self) -> PowerLawFit<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for PowerLawFit<'a>
impl<'a> Debug for PowerLawFit<'a>
Source§impl<'a> PartialEq for PowerLawFit<'a>
impl<'a> PartialEq for PowerLawFit<'a>
Source§fn eq(&self, other: &PowerLawFit<'a>) -> bool
fn eq(&self, other: &PowerLawFit<'a>) -> bool
self and other values to be equal, and is used by ==.