nichesphere.niche_stats.community_edge_stats

nichesphere.niche_stats.community_edge_stats#

nichesphere.niche_stats.community_edge_stats(g: Graph, partition: dict) → dict#

Per-community positive/negative edge count and weight statistics.

For each community the following are computed, distinguishing internal edges (both endpoints in the same community) from external ones (endpoints in different communities), and positive weights from negative:

  • internal_pos_count, internal_pos_weight

  • internal_neg_count, internal_neg_weight

  • external_pos_count, external_pos_weight

  • external_neg_count, external_neg_weight

  • external_by_community – nested dict {other_community: {pos_count, pos_weight, neg_count, neg_weight}} for pairwise breakdowns.

Counts are numbers of edges (unweighted); weights are sums of absolute edge weights (A_neg already stores absolute values, per _adjacency_from_graph()). External edges are attributed to both communities they connect.

Parameters:
  • g (nx.Graph) – Signed co-localization network (output of nichesphere.coloc.colocNW()).

  • partition (dict) – Mapping of node → community name (e.g. vc_map_named).

Returns:

stats – Keyed by community name; each value is a dict of the metrics listed above.

Return type:

dict