nng | R Documentation |
nearest neighbor, k-nearest neighbor, and mutual k-nearest neighbor (di)graphs.
nng(x = NULL, dx = NULL, k = 1, mutual = FALSE, method = NULL, use.fnn = FALSE, algorithm = 'cover_tree')
x |
a data matrix. Either x or dx is required |
dx |
interpoint distance matrix |
k |
number of neighbors |
mutual |
logical. if true the neighbors must be mutual. See details. |
method |
the method used for the distance.
See |
use.fnn |
logical. If TRUE, |
algorithm |
see |
a k-nearest neighbor graph is a digraph where each vertex is associated with an observation and there is a directed edge between the vertex and it's k nearest neighbors. A mutual k-nearest neighbor graph is a graph where there is an edge between x and y if x is one of the k nearest neighbors of y AND y is one of the k nearest neighbors of x.
an object of class igraph with the extra attributes
layout |
the x vectors. |
k,mutual,p |
arguments given to |
David J. Marchette david.marchette@navy.mil
D.J. Marchette, Random Graphs for Statistical Pattern Recognition, John Wiley & Sons, 2004.
dist
get.knn
x <- matrix(runif(100),ncol=2) G1 <- nng(x,k=1) ## Not run: par(mfrow=c(2,2)) plot(G1) ## End(Not run) G2 <- nng(x,k=2) ## Not run: plot(G2) ## End(Not run) G5 <- nng(x,k=5) ## Not run: plot(G5) ## End(Not run) G5m <- nng(x,k=5,mutual=TRUE) ## Not run: plot(G5m) par(mfrow=c(1,1)) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.