nnct.boot.dis: Bootstrap Nearest Neighbor Contingency Table (NNCT)

View source: R/NNCTFunctions.R

nnct.boot.disR Documentation

Bootstrap Nearest Neighbor Contingency Table (NNCT)

Description

Returns the k \times k NNCT with sampling replacement of the points for each base point. That is, for each base point, the rows in the IPD matrix are sampled with replacement and the NN counts are updated accordingly. Row and columns of the NNCT are labeled with the corresponding class labels.

The argument self is a logical argument (default=TRUE) for including the base point in the resampling or not. If TRUE, for each base point all entries in the row are sampled (with replacement) so, the point itself can also be sampled multiple times and if FALSE the point is excluded from the resampling (i.e., other points are sampled with replacement).

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.

Usage

nnct.boot.dis(x, lab, self = TRUE, ties = TRUE, 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).

lab

The vector of class labels (numerical or categorical)

self

A logical argument (default=TRUE). If TRUE, for each base point, all entries in the row are sampled (with replacement) and if FALSE the point is excluded from the resampling (i.e., other points are sampled with replacement).

ties

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.

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 the k \times k NNCT where k is the number of classes in the data set with sampling replacement of the rows of the IPD matrix.

Author(s)

Elvan Ceyhan

See Also

nnct and nnct.sub

Examples

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.boot.dis(ipd,cls)
nnct.boot.dis(Y,cls,is.ipd = FALSE) 
#may give different result from above due to random sub-sampling
nnct.boot.dis(ipd,cls,self = FALSE)
nnct.boot.dis(ipd,cls,ties = FALSE) 
#differences are due to ties and resampling of distances

#cls as a factor
na<-floor(n/2); nb<-n-na
fcls<-rep(c("a","b"),c(na,nb))
nnct.boot.dis(ipd,fcls)

#cls as an unsorted factor
fcls<-sample(c("a","b"),n,replace = TRUE)
nnct.boot.dis(ipd,fcls)

fcls<-sort(fcls)
nnct.boot.dis(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))
nnct.boot.dis(ipd,cls)

#cls as a factor
fcls<-rep(letters[1:4],rep(10,4))
nnct.boot.dis(ipd,fcls)

#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.boot.dis(ipd,cls)

#cls as a factor
na<-floor(n/2); nb<-n-na
fcls<-rep(c("a","b"),c(na,nb))
nnct.boot.dis(ipd,fcls)

#with possible ties in the data
Y<-matrix(round(runif(3*n)*10),ncol=3)
ipd<-ipd.mat(Y)
cls<-sample(1:2,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
nnct.boot.dis(ipd,cls)
nnct.boot.dis(ipd,cls,self = FALSE)
nnct.boot.dis(ipd,cls,ties = FALSE) 
#differences are due to ties and resampling of distances


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