Learn R Programming

nnspat (version 0.1.2)

sharedNNmc: The Shared NN Vectors for Multiple Classes

Description

Returns a matrix with \(k\) rows where each row is the vector of number of points with shared NNs, \(Q_i=(Q_{i0},Q_{i1},\ldots)\) where \(Q_{ij}\) is the number of class \(i\) points that are NN to class \(j\) points. The function also returns the indices of columns with nonzero sums as a vector.

The output matrix of shared NNs is used in testing symmetry in shared NN structure (i.e., \(Q\)-symmetry or Pielou's second type of symmetry), e.g., in functions Qsym.ct and Qsym.test.

See also (pielou:1961,ceyhan:SWJ-spat-sym2014;textualnnspat) and the references therein.

Usage

sharedNNmc(x, lab, is.ipd = TRUE, ...)

Value

The function Qval returns the \(Q\) value

The function Qvec returns a list with two elements

q

the \(Q\) value, the number of shared NNs

qvec

the vector of \(Q_j\) values

The function sharedNN returns a matrix with 2 rows, where first row is the \(j\) values and second row is the corresponding vector of \(Q_j\) values

The function Rval returns the \(R\) value, the number of reflexive NNs.

Returns a list with two elements

Nv

A \(k\)-row matrix of shared NNs by class where each row of the matrix is the vector of number of points with shared NNs \(Q_i=(Q_{i0},Q_{i1},\ldots)\) where \(Q_{ij}\) is the number of class \(i\) points that are NN to \(j\) points.

col.ind

The vector of indices of columns with nonzero sums

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)

is.ipd

A logical parameter (default=TRUE). If TRUE, x is taken as the inter-point distance matrix (IPD 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.

Author

Elvan Ceyhan

References

See Also

Qval, Qvec and sharedNN

Examples

Run this code
n<-20  #or try sample(1:20,1)
Y<-matrix(runif(3*n),ncol=3)
cls<-sample(1:2,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
ipd<-ipd.mat(Y)

sharedNNmc(ipd,cls)
sharedNNmc(Y,cls,is.ipd = FALSE)
sharedNNmc(Y,cls,is.ipd = FALSE,method="max")

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

#############
n<-40
Y<-matrix(runif(3*n),ncol=3)
cls<-sample(1:4,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
ipd<-ipd.mat(Y)

sharedNNmc(ipd,cls) 

Run the code above in your browser using DataLab