spanning_tree: Minimum or Maximum Spanning Tree

View source: R/wrangle-structure.R

spanning_treeR Documentation

Minimum or Maximum Spanning Tree

Description

Computes a spanning tree with Prim's algorithm on each connected component, so a disconnected network yields a spanning forest. A directed network is symmetrized first, each pair taking the larger of its two arc weights. Self-loops are ignored. Missing or infinite weights raise a cograph_bad_selection error.

Usage

spanning_tree(
  x,
  weights = c("weight", "none"),
  maximum = FALSE,
  keep_format = FALSE,
  directed = NULL
)

Arguments

x

Network input.

weights

"weight" (default) uses the edge weights as costs; "none" treats every edge as cost 1.

maximum

Logical. Find the maximum spanning tree instead of the minimum. Default FALSE. Set TRUE when the weights are similarities.

keep_format

Logical. If TRUE, a matrix, igraph, statnet network or tna input is returned in its own format. An edge-list data frame or a qgraph object is returned as a cograph_network with a cograph_no_format_roundtrip warning. Default FALSE returns a cograph_network.

directed

Logical or NULL. Directedness used to read the input. NULL (default) detects it from the input. The tree itself is undirected.

Value

An undirected cograph_network holding the spanning tree (or forest), or the input format when keep_format = TRUE. Every node is kept.

References

Prim, R. C. (1957). Shortest connection networks and some generalizations. Bell System Technical Journal, 36(6), 1389–1401.

See Also

disparity_filter, threshold_edges

Examples

spanning_tree(regulation_net, maximum = TRUE)

cograph documentation built on Nov. 19, 2026, 5:07 p.m.