funs.kNNdist2cl | R Documentation |
k
NN distancesTwo functions: kthNNdist2cl
and kNNdist2cl
.
kthNNdist2cl
returns the distances between subjects from class i and their k^{th} NNs from class j.
The output is a list
with first entry (kth.nndist
) is an n_i \times 3 matrix where n_i is the size of class i
and first column is the subject index for class i,
second column is the index of the k^{th} NN of class i subjects among class j subjects and third column
contains the corresponding k^{th} NN distances. The other entries in the list
are labels of base class and NN class
and the value of k
, respectively.
kNNdist2cl
returns the distances between subjects from class i and their k
NNs from class j.
The output is a list
with first entry (ind.knndist
) is an n_i \times (k+1) matrix where n_i is the size of class i,
first column is the indices of class i subjects, 2nd to (k+1)-st columns are the indices of k
NNs of class i
subjects among class j subjects. The second list
entry (knndist
) is an n_i \times k matrix where n_i is the
size of class i and the columns are the k
NN distances of class i subjects to class j subjects.
The other entries in the list
are labels of base class and NN class and the value of k
, respectively.
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.
kthNNdist2cl(x, k, i, j, lab, within.class.ind = FALSE, is.ipd = TRUE, ...) kNNdist2cl(x, k, i, j, lab, within.class.ind = FALSE, is.ipd = TRUE, ...)
x |
The IPD matrix (if |
k |
Integer specifying the number of NNs (of subjects). |
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 |
kthNNdist2cl
returns the list
of elements
kth.nndist |
n_i \times 3 matrix where n_i is the size of class i
and first column is the subject index for class i, second column is the index of the |
base.class |
label of base class |
nn.class |
label of NN class |
k |
value of |
kNNdist2cl
returns the list
of elements
ind.knndist |
n_i \times (k+1) matrix where n_i is the size of class i, first column is the indices of class i subjects, 2nd to (k+1)-st columns are the indices of k NNs of class i subjects among class j subjects. |
knndist |
n_i \times k matrix where n_i is the size of class i and the columns are the kNN distances of class i subjects to class j subjects. |
base.class |
label of base class |
nn.class |
label of NN class |
k |
value of |
Elvan Ceyhan
NNdist2cl
, kthNNdist
and kNNdist
#Examples for kthNNdist2cl #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) kthNNdist2cl(ipd,3,1,2,clab) kthNNdist2cl(Y,3,1,2,clab,is.ipd = FALSE) kthNNdist2cl(ipd,3,1,2,clab,within = TRUE) #three class case clab<-sample(1:3,n,replace=TRUE) #class labels table(clab) kthNNdist2cl(ipd,3,2,3,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) kthNNdist2cl(ipd,3,1,2,clab) # here kthNNdist2cl(ipd,3,1,12,clab) #gives an error message kthNNdist2cl(ipd,3,"1",2,clab) #Examples for kNNdist2cl #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) kNNdist2cl(ipd,3,1,2,clab) kNNdist2cl(Y,3,1,2,clab,is.ipd = FALSE) kNNdist2cl(ipd,3,1,2,clab,within = TRUE) #three class case clab<-sample(1:3,n,replace=TRUE) #class labels table(clab) kNNdist2cl(ipd,3,1,2,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) kNNdist2cl(ipd,3,1,2,clab) kNNdist2cl(ipd,3,"1",2,clab) #here kNNdist2cl(ipd,3,"a",2,clab) #gives an error message
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.