# exact.nnct: Exact version of Pearson's chi-square test on NNCTs In nnspat: Nearest Neighbor Methods for Spatial Patterns

 exact.nnct R Documentation

## Exact version of Pearson's chi-square test on NNCTs

### Description

An object of class "htest" performing exact version of Pearson's chi-square test on nearest neighbor contingency tables (NNCTs) for the RL or CSR independence for 2 classes. Pearson's χ^2 test is based on the test statistic \mathcal X^2=∑_{j=1}^2∑_{i=1}^2 (N_{ij}-μ_{ij})^2/μ_{ij}, which has χ^2_1 distribution in the limit provided that the contingency table is constructed under the independence null hypothesis. The exact version of Pearson's test uses the exact distribution of \mathcal X^2 rather than large sample χ^2 approximation. That is, for the one-sided alternative, we calculate the p-values as in the function exact.pval1s; and for the two-sided alternative, we calculate the p-values as in the function exact.pval2s with double argument determining the type of the correction.

This test would be equivalent to Fisher's exact test fisher.test if the odds ratio=1 (which can not be specified in the current version), and the odds ratio for the RL or CSR independence null hypothesis is θ_0=(n_1-1)(n_2-1)/(n_1 n_2) which is used in the function and the p-value and confidence interval computations are are adapted from fisher.test.

See \insertCiteceyhan:SWJ-spat-sym2014;textualnnspat for more details.

### Usage

exact.nnct(
ct,
alternative = "two.sided",
conf.level = 0.95,
pval.type = "inc",
double = FALSE
)


### Arguments

 ct A 2 \times 2 NNCT alternative Type of the alternative hypothesis in the test, one of "two.sided", "less" or "greater". conf.level Level of the upper and lower confidence limits, default is 0.95, for the odds ratio pval.type The type of the p-value correction for the exact test on the NNCT, default="inc". Takes on values "inc", "exc", "mid", "tocher" (or equivalently 1-4, respectively) for table inclusive, table-exclusive, mid-p-value, and Tocher corrected p-value, respectively. double A logical argument (default is FALSE) to determine whether type I or II correction should be applied to the two-sided p-value. Used only when alternative="two.sided". If TRUE type I correction (for doubling the minimum of the one-sided p-value) is applied, otherwise, type II correction (using the probabilities for the more extreme tables) is applied.

### Value

A list with the elements

 statistic The test statistic, it is NULL for this function p.value The p-value for the hypothesis test for the corresponding alternative conf.int Confidence interval for the odds ratio in the 2 \times 2 NNCT at the given confidence level conf.level and depends on the type of alternative. estimate Estimate, i.e., the observed odds ratio the 2 \times 2 NNCT. null.value Hypothesized null value for the odds ratio in the 2 \times 2 NNCT, which is θ_0=(n_1-1)(n_2-1)/(n_1 n_2) for this function. alternative Type of the alternative hypothesis in the test, one of "two.sided", "less", "greater" method Description of the hypothesis test data.name Name of the contingency table, ct

Elvan Ceyhan

### References

\insertAllCited

fisher.test, exact.pval1s, and exact.pval2s

### Examples

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)
ct

exact.nnct(ct)
fisher.test(ct)

exact.nnct(ct,alt="g")
fisher.test(ct,alt="g")

exact.nnct(ct,alt="l",pval.type = "mid")

#############
ct<-matrix(sample(10:20,9),ncol=3)
fisher.test(ct) #here exact.nnct(ct) gives error message, since number of classes > 2



nnspat documentation built on Aug. 30, 2022, 9:06 a.m.