NNdist: Distances between subjects and their NNs

View source: R/NNCTFunctions.R

NNdistR Documentation

Distances between subjects and their NNs

Description

Returns the distances between subjects and their NNs. The output is an n \times 2 matrix where n is the data size and first column is the subject index and second column contains the corresponding distances to NN subjects.

The argument is.ipd is a logical argument (default=TRUE) to determine the structure of the argument x. If TRUE, x is taken to be the inter-point distance (IPD) matrix, and if FALSE, x is taken to be the data set with rows representing the data points.

Usage

NNdist(x, is.ipd = TRUE, ...)

Arguments

x

The IPD matrix (if is.ipd=TRUE) or a data set of points in matrix or data frame form where points correspond to the rows (if is.ipd = FALSE).

is.ipd

A logical parameter (default=TRUE). If TRUE, x is taken as the inter-point distance matrix, otherwise, x is taken as the data set with rows representing the data points.

...

are for further arguments, such as method and p, passed to the dist function.

Value

Returns an n \times 2 matrix where n is data size (i.e., number of subjects) and first column is the subject index and second column is the NN distances.

Author(s)

Elvan Ceyhan

See Also

kthNNdist, kNNdist, and NNdist2cl

Examples

#3D data points
n<-20  #or try sample(1:20,1)
Y<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(Y)
NNdist(ipd)
NNdist(Y,is.ipd = FALSE)
NNdist(Y,is.ipd = FALSE,method="max")

#1D data points
X<-as.matrix(runif(5)) # need to be entered as a matrix with one column
#(i.e., a column vector), hence X<-runif(5) would not work
ipd<-ipd.mat(X)
NNdist(ipd)
NNdist(X,is.ipd = FALSE)


nnspat documentation built on May 29, 2024, 10:03 a.m.