nnct: Nearest Neighbor Contingency Table (NNCT)

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/NNCTFunctions.r

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 (\insertCitedixon:1994,dixon:NNCTEco2002,ceyhan:eest-2010,ceyhan:jkss-posthoc-2017;textualnnspat) and the references therein.

Usage

1
nnct(x, lab, ties = FALSE, 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 = FALSEALSE).

lab

The vector of class labels (numerical or categorical)

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.

Author(s)

Elvan Ceyhan

References

\insertAllCited

See Also

nnct.sub, scct, rct, and tct

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)

nnspat documentation built on May 10, 2021, 9:06 a.m.