NNdist2cl: Distances between subjects from class i and their NNs from...

View source: R/NNCTFunctions.R

NNdist2clR Documentation

Distances between subjects from class i and their NNs from class j

Description

Returns the distances between subjects from class i and their nearest neighbors (NNs) from class j. The output is a list with first entry (nndist) being an n_i \times 3 matrix where n_i is the size of class i and first column is the subject index in class i, second column is the subject index in NN class j, and third column contains the corresponding distances of each class i subject to its NN among class j subjects. Class i is labeled as base class and class j is labeled as NN class.

The argument within.class.ind is a logical argument (default=FALSE) to determine the indexing of the class i subjects. If TRUE, index numbering of subjects is within the class, from 1 to class size (i.e., 1:n_i), according to their order in the original data; otherwise, index numbering within class is just the indices in the original data.

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

NNdist2cl(x, i, j, lab, within.class.ind = FALSE, 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).

i, j

class label of base class and NN classes, respectively.

lab

The vector of class labels (numerical or categorical)

within.class.ind

A logical parameter (default=FALSE). If TRUE, index numbering of subjects is within the class, from 1 to class size (i.e., 1:n_i), according to their order in the original data; otherwise, index numbering within class is just the indices in the original data.

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 a list with three elements

nndist

n_i \times 3 matrix where n_i is the size of class i and first column is the subject index in class i, second column is the subject index in NN class j, and third column contains the corresponding distances of each class i subject to its NN among class j subjects.

base.class

label of base class

nn.class

label of NN class

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)
#two class case
clab<-sample(1:2,n,replace=TRUE) #class labels
table(clab)
NNdist2cl(ipd,1,2,clab)
NNdist2cl(Y,1,2,clab,is.ipd = FALSE)

NNdist2cl(ipd,1,2,clab,within = TRUE)

#three class case
clab<-sample(1:3,n,replace=TRUE) #class labels
table(clab)
NNdist2cl(ipd,2,1,clab)

#1D data points
n<-15
X<-as.matrix(runif(n))# need to be entered as a matrix with one column
#(i.e., a column vector), hence X<-runif(n) would not work
ipd<-ipd.mat(X)
#two class case
clab<-sample(1:2,n,replace=TRUE) #class labels
table(clab)
NNdist2cl(ipd,1,2,clab)
NNdist2cl(X,1,2,clab,is.ipd = FALSE)


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