View source: R/NNCTFunctions.R
| nnct.sub | R Documentation | 
Returns the k \times k NNCT with (only) base points are restricted 
to be in the subset of indices ss using
the IPD matrix or data set x where k is 
the number of classes in the data set. 
That is, the base points
are the points with indices in ss 
but for the NNs the function checks all the points in the data set 
(including the points in ss). 
Row and columns of the NNCT are labeled with 
the corresponding class labels.
The argument ties is a logical argument 
(default=FALSE) to take ties into account or not. 
If TRUE a NN contributes 1/m to the NN count 
if it is one of the m tied NNs of a subject.
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.
nnct.sub(ss, x, lab, ties = FALSE, is.ipd = TRUE, ...)
| ss | indices of subjects (i.e., row indices in the data set) chosen to be the base points | 
| x | The IPD matrix (if  | 
| lab | The  | 
| ties | A logical argument (default= | 
| is.ipd | A logical parameter (default= | 
| ... | are for further arguments, 
such as  | 
Returns the k \times k NNCT 
where k is the number of classes in the data set with (only) base points
restricted to a subsample ss.
Elvan Ceyhan
nnct and nnct.boot.dis
n<-20  #or try sample(1:20,1)
Y<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(Y)
cls<-sample(1:2,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
nnct(ipd,cls)
#subsampling indices
ss<-sample(1:n,floor(n/2))
nnct.sub(ss,ipd,cls)
nnct.sub(ss,Y,cls,is.ipd = FALSE)
nnct.sub(ss,ipd,cls,ties = TRUE)
#cls as a factor
na<-floor(n/2); nb<-n-na
fcls<-rep(c("a","b"),c(na,nb))
nnct.sub(ss,ipd,fcls)
#cls as an unsorted factor
fcls<-sample(c("a","b"),n,replace = TRUE)
nnct(ipd,fcls)
nnct.sub(ss,ipd,fcls)
fcls<-sort(fcls)
nnct.sub(ss,ipd,fcls)
#############
n<-40
Y<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(Y)
cls<-sample(1:4,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
ss<-sample(1:40,30)
nnct.sub(ss,ipd,cls)
#cls as a factor
fcls<-rep(letters[1:4],rep(10,4))
nnct.sub(ss,ipd,cls)
#1D data points
n<-20  #or try sample(1:20,1)
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)
cls<-sample(1:2,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
nnct(ipd,cls)
#subsampling indices
ss<-sample(1:n,floor(n/2))
nnct.sub(ss,ipd,cls)
#with possible ties in the data
Y<-matrix(round(runif(120)*10),ncol=3)
ipd<-ipd.mat(Y)
cls<-sample(1:4,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
ss<-sample(1:40,30)
nnct.sub(ss,ipd,cls)
nnct.sub(ss,ipd,cls,ties = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.