View source: R/NNCTFunctions.r
NNdist2cl | R Documentation |
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.
NNdist2cl(x, i, j, lab, within.class.ind = FALSE, is.ipd = TRUE, ...)
x |
The IPD matrix (if |
i, j |
class label of base class and NN classes, respectively. |
lab |
The |
within.class.ind |
A logical parameter (default= |
is.ipd |
A logical parameter (default= |
... |
are for further arguments, such as |
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 |
Elvan Ceyhan
kthNNdist
, kNNdist
, and NNdist2cl
#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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.