Skip to main content

assortativity_nominal

Function assortativity_nominal 

Source
pub fn assortativity_nominal(
    graph: &Graph,
    types: &[u32],
    directed: bool,
    normalized: bool,
) -> IgraphResult<f64>
Expand description

Compute categorical (nominal) assortativity coefficient.

Given integer category labels for each vertex, measures whether edges tend to connect vertices of the same type (positive) or different types (negative). The coefficient ranges from -1 to 1: +1 means all edges stay within categories, 0 means random mixing, -1 means perfectly disassortative.

The unnormalized version equals the modularity.

  • types: integer category label for each vertex (0-based, length must equal vertex count).
  • directed: if true and the graph is directed, respect edge direction; otherwise treat as undirected (each edge counted in both directions).
  • normalized: if true, return the standard normalized assortativity; if false, return the unnormalized version (= modularity).

Returns f64::NAN for graphs with no vertices or no edges.

§References

M. E. J. Newman: Mixing patterns in networks, Phys. Rev. E 67, 026126 (2003).

§Examples

use rust_igraph::{Graph, assortativity_nominal};

// Perfect assortative: all edges within same type
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap(); // type 0 - type 0
g.add_edge(2, 3).unwrap(); // type 1 - type 1
let types = vec![0u32, 0, 1, 1];
let r = assortativity_nominal(&g, &types, false, true).unwrap();
assert!(r > 0.99); // close to 1.0