constructGraph: Construct a Graph Object from Coordinate Data using K-Nearest...

View source: R/functions.R

constructGraphR Documentation

Construct a Graph Object from Coordinate Data using K-Nearest Neighbors

Description

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.

Usage

constructGraph(coordinates, k)

Arguments

coordinates

Data frame whose first 2 columns are numeric coordinate data

k

Integer, the parameter for the K-Nearest Neighbors algorithm

Details

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.

Value

An object of class 'graph' from the igraph package

References

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.

Examples

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)

rayisaacalan/BASTION documentation built on April 27, 2023, 2:06 p.m.