sharedNNmc {nnspat}R Documentation

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 (2014)) and the references therein.

Usage

sharedNNmc(x, lab, 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)

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.

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

Author(s)

Elvan Ceyhan

References

Ceyhan E (2014). “Testing Spatial Symmetry Using Contingency Tables Based on Nearest Neighbor Relations.” The Scientific World Journal, Volume 2014, Article ID 698296.

Pielou EC (1961). “Segregation and symmetry in two-species populations as studied by nearest-neighbor relationships.” Journal of Ecology, 49(2), 255-269.

See Also

Qval, Qvec and sharedNN

Examples

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) 


[Package nnspat version 0.1.2 Index]