Learn R Programming

spqdep (version 0.1.3.3)

local.jc.test: A function to calculate the local Join Count tests.

Description

This function calculates the local Join Count tests.This function is a wrapper of local_joincount in rgeoda package.

Usage

local.jc.test(formula = NULL, data = NULL, fx = NULL, case = NULL, coor = NULL,
 listw = listw, nsim = 999, control = list())

Value

The output is an object of the class localjc


local.SRQ A matrix with

nnnumber of neighbourhood in the localization 'i'.
ljclocal Join Count statistics.
pseudo.valuep-value of local jc tests.

Arguments

formula

An (optional) formula with the factor included in data

data

An (optional) data frame or a sf object containing the variable to testing for.

fx

An (optional) factor of observations with the same length as the neighbours list in listw

case

level of the factor used to obtain the local Join Count test. See details.

coor

(optional) a 2xN vector with spatial coordinates. Used when *data* is not a spatial object.

listw

A neighbourhood list (an object type knn, listw or nb).

nsim

The number of permutation to obtain the local Join Count tests. Default value 999.

control

Optional argument. See Control argument section.

Control arguments

seedinitNumerical value for the seed in boot version. Default value seedinit = 123

Author

Fernando Lópezfernando.lopez@upct.es
Román Mínguezroman.minguez@uclm.es
Antonio Páezpaezha@gmail.com
Manuel Ruizmanuel.ruiz@upct.es

Details

This test develop by Anselin and Li (2019) can be apply only for binary variables (usually named B and W), and count the number of joins of type B-B where the proportion of observations with B is lower than half. The interest lies in identifying co-occurrences of uncommon events, i.e., situations where observations that take on the value of B constitute much less than half of the sample.
The statistic is defined as:
$$BB_i = x_i \sum_j{w_{ij}x_j}$$
only meaningful for those observations where \(x_i=1\), since for \(x_i=0\) the result will always equal zero.

The object listw can be the class:

  • knn: Objects of the class knn that consider the neighbours in order of proximity.

  • nb: If the neighbours are obtained from an sf object, the code internally will call the function nb2nb_order it will order them in order of proximity of the centroids.

  • matrix: If a object of matrix class based in the inverse of the distance in introduced as argument, the function nb2nb_order will also be called internally to transform the object the class matrix to a matrix of the class nb with ordered neighbours.

References

  • Anselin, L., and Li, X. (2019). Operational local join Count statistics for cluster detection. Journal of Geographical Systems, 21(2), 189-210.

See Also

local.sp.runs.test, dgp.spq

Examples

Run this code

# Case 1: Local spatial runs test based on knn
N <- 100
cx <- runif(N)
cy <- runif(N)
coor <- cbind(cx,cy)
listw <- spdep::knearneigh(coor, k = 4)
p <- c(1/2,1/2)
rho <- 0.5
fx <- dgp.spq(p = p, listw = listw, rho = rho)
ljc <- local.jc.test(fx = fx, coor = coor, case= "A", listw = listw)
print(ljc)
plot(ljc, coor = coor, sig = 0.1)

# \donttest{
# Case 2:Fastfood example. sf (points)
data("FastFood.sf")
# sf::sf_use_s2(FALSE)
x <- sf::st_coordinates(sf::st_centroid(FastFood.sf))
listw <- spdep::knearneigh(x, k = 6)
formula <- ~ Type
ljc <- local.jc.test(formula = formula, data = FastFood.sf, case = "H",listw = listw)
print(ljc)
plot(ljc, sf = FastFood.sf, sig = 0.05)

# Case 3: With a sf object (poligons)
fname <- system.file("shape/nc.shp", package="sf")
nc <- sf::st_read(fname)
listw <- spdep::poly2nb(as(nc,"Spatial"), queen = FALSE)
p <- c(1/3,2/3)
rho = 0.5
nc$fx <- dgp.spq(p = p, listw = listw, rho = rho)
plot(nc["fx"])
formula <- ~ fx
ljc <- local.jc.test(formula = formula, data = nc, case = "A", listw = listw)
ljc
plot(ljc, sf = nc)

# Case 4: With isolated areas
data(provinces_spain)
# sf::sf_use_s2(FALSE)
listw <- spdep::poly2nb(as(provinces_spain,"Spatial"), queen = FALSE)
provinces_spain$Mal2Fml<- factor(provinces_spain$Mal2Fml > 100)
levels(provinces_spain$Mal2Fml) = c("men","woman")
formula <- ~ Mal2Fml
ljc <- local.jc.test(formula = formula, data = provinces_spain, listw = listw)
print(ljc)
plot(ljc, sf = provinces_spain, sig = 0.1)

# Case 5: Regular lattice
data(Boots.sf)
listw <- spdep::poly2nb(as(Boots.sf,"Spatial"), queen = TRUE)
formula <- ~ BW
ljc <- local.jc.test(formula = formula, data = Boots.sf, case="B", listw = listw)
print(ljc)
plot(ljc, sf = Boots.sf, sig = 0.05)
lsr <- local.sp.runs.test(formula = formula, data = Boots.sf,
distr = "bootstrap", nsim= 99, listw = listw)
print(lsr)
plot(lsr, sf = Boots.sf, sig = 0.1)
scan <- scan.test(formula = formula, data = Boots.sf, nsim = 299,
dist = "bernoulli", nv = 60 , case = "B", windows = "elliptic")
plot(scan, sf = Boots.sf)
# }

Run the code above in your browser using DataLab