View source: R/mst_completion_graphs.R
| create.cmst.graph | R Documentation |
Constructs a completion of the Minimal Spanning Tree (MST) graph from a numeric data matrix. The graph is constructed in two steps: first, a MST is built connecting all data points using minimal total edge length; then, additional edges are added between any pair of points whose Euclidean distance is less than or equal to a quantile threshold based on the MST edge length distribution.
create.cmst.graph(
X,
q.thld = 0.9,
pca.dim = 100,
variance.explained = 0.99,
verbose = TRUE
)
X |
A numeric matrix or data frame of shape |
q.thld |
Numeric scalar between 0 and 1 (exclusive). The quantile threshold for MST completion. Edges are added between points whose distance is less than or equal to the q.thld-quantile of MST edge weights. Default is 0.9. |
pca.dim |
Positive integer or NULL. If provided and |
variance.explained |
Numeric between 0 and 1 (exclusive) or NULL. If
provided, selects the minimal number of PCA components such that this
proportion of total variance is retained (up to |
verbose |
Logical. If |
The MST completion process enhances connectivity in the original MST by adding edges between vertices that are "close" according to the distance distribution in the MST. This can be useful for creating more robust graph representations of data that maintain local structure while avoiding long-range connections.
When PCA is applied (either through pca.dim or variance.explained),
the data is first centered and projected onto the leading principal components
before graph construction. This can significantly reduce computation time
for high-dimensional data while preserving the most important variation.
An object of class mst_completion_graph, which is a list
containing:
mst_adj_listA list of length n, where element i contains the indices of vertices adjacent to vertex i in the MST.
mst_weight_listA list of length n, where element i
contains the edge weights corresponding to the adjacent vertices in
mst_adj_list[[i]].
cmst_adj_listA list of length n containing adjacency information for the completed MST graph.
cmst_weight_listA list of length n containing edge weights for the completed MST graph.
mst_edge_weightsNumeric vector containing all unique MST edge weights.
cmst_distance_thresholdNumeric scalar containing the actual Euclidean distance threshold used for completion.
The returned object also has the following attributes:
q_thldThe quantile threshold used for MST completion.
pcaIf PCA was applied, a list containing:
original_dim: The original number of dimensions
n_components: The number of PCA components used
variance_explained: The proportion of variance explained
cumulative_variance: Cumulative variance by component (if applicable)
callThe matched function call.
Gower, J. C., & Ross, G. J. S. (1969). Minimum spanning trees and single linkage cluster analysis. Applied Statistics, 18(1), 54-64.
stats::prcomp() for principal component analysis.
set.seed(123)
X <- matrix(rnorm(60), nrow = 20, ncol = 3)
graph <- create.cmst.graph(X, verbose = FALSE)
graph$n_vertices
graph$n_edges
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.