constructGraph | R Documentation |
constructGraph
takes numeric data (currently it requires 2 dimensional data such as spatial data,
this functionality will expand in a future update) and uses the K-Nearest Neighbors algorithm to
construct a weighted graph object from igraph
. The K-Nearest Neighbors implementation is from
cccd
.
constructGraph(coordinates, k)
coordinates |
Data frame whose first 2 columns are numeric coordinate data |
k |
Integer, the parameter for the K-Nearest Neighbors algorithm |
Note: this function is not guaranteed to return a connected graph, and connectivity is highly recommended for graphs to be used in other functions. If the output graph is not connected, it is recommended to add more data points, increase k, or construct a graph manually.
An object of class 'graph' from the igraph
package
Csardi G, Nepusz T: The igraph software package for complex network research, InterJournal, Complex Systems 1695. 2006. https://igraph.org
David J. Marchette (2015). cccd: Class Cover Catch Digraphs. R package version 1.5. https://CRAN.R-project.org/package=cccd
Luo, Z.T. (*), Sang, H. and Mallick, B.K. (2021), BAST: Bayesian Additive Regression Spanning Trees for Complex Constrained Domain
Luo, Z.T. (*), Sang, H. and Mallick, B.K. (2021), A Bayesian Contiguous Partitioning Method for Learning Clustered Latent Variables, Journal of Machine Learning Research, 22, 1-52.
set.seed(1)
coords = data.frame(lon = rnorm(50), lat = rnorm(50))
g = constructGraph(coords, 4)
plot(g, layout = as.matrix(coords), edge.arrow.mode = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.