nnct {nnspat} | R Documentation |
Nearest Neighbor Contingency Table (NNCT)
Description
Returns the k \times k
NNCT given the IPD matrix or data set x
where k
is the number of classes in the data set.
Rows 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.
See also (Dixon (1994, 2002); Ceyhan (2010, 2017)) and the references therein.
Usage
nnct(x, lab, ties = FALSE, is.ipd = TRUE, ...)
Arguments
x |
The IPD matrix (if |
lab |
The |
ties |
A logical argument (default= |
is.ipd |
A logical parameter (default= |
... |
are for further arguments,
such as |
Value
Returns the k \times k
NNCT
where k
is the number of classes in the data set.
Author(s)
Elvan Ceyhan
References
Ceyhan E (2010).
“On the use of nearest neighbor contingency tables for testing spatial segregation.”
Environmental and Ecological Statistics, 17(3), 247-282.
Ceyhan E (2017).
“Cell-Specific and Post-hoc Spatial Clustering Tests Based on Nearest Neighbor Contingency Tables.”
Journal of the Korean Statistical Society, 46(2), 219-245.
Dixon PM (1994).
“Testing spatial segregation using a nearest-neighbor contingency table.”
Ecology, 75(7), 1940-1948.
Dixon PM (2002).
“Nearest-neighbor contingency table analysis of spatial segregation for several species.”
Ecoscience, 9(2), 142-151.
See Also
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(ipd,cls)
nnct(ipd,cls,ties = TRUE)
nnct(Y,cls,is.ipd = FALSE)
nnct(Y,cls,is.ipd = FALSE,method="max")
nnct(Y,cls,is.ipd = FALSE,method="mink",p=6)
#with one class, it works but really uninformative
cls<-rep(1,n)
nnct(ipd,cls)
#cls as a factor
na<-floor(n/2); nb<-n-na
fcls<-rep(c("a","b"),c(na,nb))
nnct(ipd,fcls)
#cls as an unsorted factor
fcls1<-sample(c("a","b"),n,replace = TRUE)
nnct(ipd,fcls1)
fcls2<-sort(fcls1)
nnct(ipd,fcls2)
#ipd needs to be sorted as well, otherwise this result will not agree with fcls1
nnct(Y,fcls1,ties = TRUE,is.ipd = FALSE)
#############
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(ipd,cls)
nnct(Y,cls,is.ipd = FALSE)
#cls as a factor
fcls<-rep(letters[1:4],rep(10,4))
nnct(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(ipd,cls)
#cls as a factor
na<-floor(n/2); nb<-n-na
fcls<-rep(c("a","b"),c(na,nb))
nnct(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(ipd,cls)
nnct(ipd,cls,ties = TRUE)