# funsNNclass.spec: NN Class-specific Chi-square Tests based on NNCTs In nnspat: Nearest Neighbor Methods for Spatial Patterns

## Description

Two functions: NN.class.spec.ct and NN.class.spec.

Both functions are objects of class "classhtest" but with different arguments (see the parameter list below). Each one performs class specific segregation tests for the columns, i.e., NN categories for k ≥ 2 classes. That is, each one performs hypothesis tests of deviations of entries in each column of NNCT from the expected values under RL or CSR for each column. Recall that column labels in the NNCT are NN class labels. The test for each column i is based on the chi-squared approximation of the corresponding quadratic form and are due to \insertCiteceyhan:stat-neer-class2009;textualnnspat.

The argument covN must be covariance of column-wise vectorization of NNCT if the logical argument byrow=FALSE otherwise the function converts covN (which is done row-wise) to columnwise version with covNrow2col function.

Each function yields the test statistic, p-value and df for each base class i, description of the alternative with the corresponding null values (i.e. expected values) for the column i, estimates for the entries in column i for i=1,…,k. The functions also provide names of the test statistics, the method and the data set used.

The null hypothesis for each column is that the corresponding N_{ij} entries in column i are equal to their expected values under RL or CSR.

## Usage

 1 2 3 NN.class.spec.ct(ct, covN, byrow = TRUE) NN.class.spec(dat, lab, ...) 

## Arguments

 ct A nearest neighbor contingency table, used in NN.class.spec.ct only covN The k^2 \times k^2 covariance matrix of column-wise vectorized entries of NNCT, ct ; used in NN.class.spec.ct only. byrow A logical argument (default=TRUE). If TRUE, rows of ct are appended to obtain the vector of N_{ij} values and covN is the covariance matrix for this vector and if FALSE columns of ct are appended to obtain the N_{ij} vector and covN is converted to the row-wise version by covNrow2col function;used in NN.class.spec.ct only. dat The data set in one or higher dimensions, each row corresponds to a data point, used in NN.class.spec only lab The vector of class labels (numerical or categorical), used in NN.class.spec only ... are for further arguments, such as method and p, passed to the dist function. used in NN.class.spec only

## Value

A list with the elements

 type Type of the class-specific test, which is "NN" for this function statistic The vector of NN class-specific test statistics stat.names Name of the test statistics p.value The vector of p-values for the hypothesis test df Degrees of freedom for the chi-squared test, which is k for this function. estimate Estimates of the parameters, transpose of the NNCT, i.e., transpose of the matrix of the observed N_{ij} values which is the transpose of NNCT. null.value Transpose of the matrix of hypothesized null values for the parameters which are expected values of the N_{ij} values in the NNCT. null.name Name of the null values method Description of the hypothesis test ct.name Name of the contingency table, ct, returned by NN.class.spec.ct only data.name Name of the data set, dat, returned by NN.class.spec only

Elvan Ceyhan

## References

\insertAllCited

base.class.spec.ct, base.class.spec, class.spec.ct and class.spec
  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 n<-20 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)) ct<-nnct(ipd,cls) W<-Wmat(ipd) Qv<-Qvec(W)$q Rv<-Rval(W) varN<-var.nnct(ct,Qv,Rv) covNrow<-cov.nnct(ct,varN,Qv,Rv) covNcol<-covNrow2col(covNrow) NN.class.spec(Y,cls) NN.class.spec(Y,cls,method="max") NN.class.spec.ct(ct,covNrow) NN.class.spec.ct(ct,covNcol,byrow = FALSE) #cls as a factor na<-floor(n/2); nb<-n-na fcls<-rep(c("a","b"),c(na,nb)) ct<-nnct(ipd,fcls) NN.class.spec(Y,fcls) NN.class.spec.ct(ct,covNrow) ############# 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)) ct<-nnct(ipd,cls) W<-Wmat(ipd) Qv<-Qvec(W)$q Rv<-Rval(W) varN<-var.nnct(ct,Qv,Rv) covNrow<-cov.nnct(ct,varN,Qv,Rv) covNcol<-covNrow2col(covNrow) NN.class.spec(Y,cls) NN.class.spec.ct(ct,covNrow) NN.class.spec.ct(ct,covNcol,byrow = FALSE)