Skip to contents

A function to compute joincount tests for spatial qualitative data. This function is a wrapper of joincount.multi and joincount.test in spdep package.

Usage

jc.test(formula = NULL,
               data = NULL,
               fx = NULL,
               listw = NULL,
               na.action,
               zero.policy = NULL,
               distr = "asymptotic",
               alternative = "greater",
               control =list())

Arguments

formula

a symbolic description of the factor(s).

data

an (optional) data frame or a sf object with points/multipolygons geometry containing the variable(s) to be tested.

fx

a factor or a matrix of factors in columns

listw

A listw object created for example by nb2listw from spdep package; if nb2listw not given, the spatial weights are built using the object given in listw argument (usually an sf object). Default = NULL.

na.action

A function (default options("na.action")), can also be na.omit or na.exclude. It may be necessary to set zero.policy to TRUE because this subsetting may create no-neighbour observations.

zero.policy

Similar to the corresponding parameter of lagsarlm function in spatialreg package. If TRUE assign zero to the lagged value of zones without neighbours. Default = NULL.

distr

character. Distribution type "asymptotic" (default) or "mc".

alternative

character string specifying the alternative hypothesis, must be one of "greater" (default), or "less".

control

list of additional arguments.

Value

An spjctest object. This type of object is a list of htest objects. The length of the list is the number of factor variables included in the formula or the number of columns in fx. Each element of the list can be a jclist object, for binomial factors, or a jcmulti object for multinomial factors. See joincount.test or joincount.multi for additional details.

Control arguments

nsimnumber of permutations used in the Monte Carlo distribution. Default nsim = 999.
seedinitseed to select the initial element during the simulations. Default seedinit = 1111.
adjust.ndefault TRUE, if FALSE the number of observations is not adjusted for no-neighbour observations, if TRUE, the number of observations is adjusted consistently. See joincount.multi for aditional information.
spChkshould the data vector names be checked against the spatial objects for identity integrity, TRUE, or FALSE, default NULL to use get.spChkOption(). See joincount.multi for aditional information.
samplingdefault nonfree, may be free. See joincount.test for additional information.
queendefault TRUE. Defines the neighborhood criteria for sf objects.
styledefines the style for listw. Default = B (binary).
knnchooses the number of neighboors when this criteria is used. Default knn = 5.

References

  • Cliff, A. D., Ord, J. K. 1981 Spatial processes, Pion, pp. 19-20.

  • Upton, G., Fingleton, B. 1985 Spatial data analysis by example: point pattern and qualitative data, Wiley, pp. 158–170.

Author

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

Examples


## Case 1
## Multinomial + Binomial using a sf multipolygon
# \donttest{
data("provinces_spain")
# sf::sf_use_s2(FALSE)
provinces_spain$Mal2Fml <- factor(provinces_spain$Mal2Fml > 100)
levels(provinces_spain$Mal2Fml) = c("men","woman")
provinces_spain$Older <- cut(provinces_spain$Older, breaks = c(-Inf,19,22.5,Inf))
levels(provinces_spain$Older) = c("low","middle","high")
f1 <- ~ Older + Mal2Fml
jc1 <- jc.test(formula = f1,
               data = provinces_spain,
               distr = "mc",
               alternative = "greater",
               zero.policy = TRUE)
#> although coordinates are longitude/latitude, st_intersects assumes that they
#> are planar
#> Warning: some observations have no neighbours;
#> if this seems unexpected, try increasing the snap argument.
#> Warning: neighbour object has 4 sub-graphs;
#> if this sub-graph count seems unexpected, try increasing the snap argument.
summary(jc1)
JoinCount Spatial Tests (Monte Carlo)
pairs pvalue Joincount Expected Variance
Older - multinomial - alternative: greater - Monte-Carlo simulation of join-count statistic (nonfree sampling)
high:high 0.41600 14 13.79 10.27
low:low 0.64900 7 8.39 7.08
middle:middle 0.54900 13 13.80 10.23
low:high 0.35200 24 22.84 14.76
middle:high 0.65000 28 29.41 19.00
middle:low 0.27400 25 22.77 16.23
Jtot 0.31500 77 75.02 22.13
Mal2Fml - binomial - alternative: greater - Monte-Carlo simulation of join-count statistic
men-men 0.48600 60 60.09 22.09
woman-woman 0.01350 13 7.28 5.97
provinces_spain$Coast <- factor(provinces_spain$Coast) levels(provinces_spain$Coast) = c("no","yes") f2 <- ~ Mal2Fml + Coast jc2 <- jc.test(formula = f2, data = provinces_spain, distr = "mc", zero.policy = TRUE) #> although coordinates are longitude/latitude, st_intersects assumes that they #> are planar #> Warning: some observations have no neighbours; #> if this seems unexpected, try increasing the snap argument. #> Warning: neighbour object has 4 sub-graphs; #> if this sub-graph count seems unexpected, try increasing the snap argument. summary(jc2)
JoinCount Spatial Tests (Monte Carlo)
pairs pvalue Joincount Expected Variance
Mal2Fml - binomial - alternative: greater - Monte-Carlo simulation of join-count statistic
men-men 0.51100 60 60.30 23.50
woman-woman 0.01200 13 7.13 5.55
Coast - binomial - alternative: greater - Monte-Carlo simulation of join-count statistic
no-no 0.00100 64 36.79 20.49
yes-yes 0.90800 14 18.92 13.49
# } # Case 2: ## Multinomial using a sf multipoint data("FastFood.sf") # sf::sf_use_s2(FALSE) f1 <- ~ Type jc3 <- jc.test(formula = f1, data = FastFood.sf, distr = "asymptotic", control = list(knn = 6)) #> Warning: neighbour object has 4 sub-graphs summary(jc3)
JoinCount Spatial Tests (asymptotic)
pairs z-value pvalue Joincount Expected Variance
Type - multinomial - alternative: greater - Join count test under nonfree sampling
H:H −4.14 0.99998 210.5 258.05 132.09
P:P −1.70 0.95580 292.5 313.38 150.13
S:S −4.05 0.99997 256.0 305.14 147.60
P:H 1.44 0.07503 596.0 570.72 308.52
S:H 3.02 0.00126 616.0 563.18 305.44
S:P 2.17 0.01482 660.0 620.53 329.37
Jtot 5.19 0.00000 1872.0 1,754.43 513.30
# Examples function joincount.test data(oldcol, package = "spdep") HICRIME <- cut(COL.OLD$CRIME, breaks = c(0,35,80), labels = c("low","high")) names(HICRIME) <- rownames(COL.OLD) jc4 <- jc.test(fx = HICRIME, listw = spdep::nb2listw(COL.nb, style="B")) summary(jc4)
JoinCount Spatial Tests (asymptotic)
pairs z-value pvalue Joincount Expected Variance
fx - binomial - alternative: greater - Join count test under nonfree sampling
high-high 6.33 0.00000 54 27.22 17.89
low-low 1.01 0.15527 34 29.59 18.90
high-low −6.09 1.00000 28 59.18 26.23
jc5 <- jc.test(fx = HICRIME, listw = spdep::nb2listw(COL.nb, style="B"), distr = "mc") summary(jc5)
JoinCount Spatial Tests (Monte Carlo)
pairs pvalue Joincount Expected Variance
fx - binomial - alternative: greater - Monte-Carlo simulation of join-count statistic
high-high 0.00100 54 27.40 17.82
low-low 0.15450 34 29.42 19.30
HICRIME <- cut(COL.OLD$CRIME, breaks = c(0, 35, 80), labels = c("low","high")) names(HICRIME) <- rownames(COL.OLD) jc6 <- jc.test(fx = HICRIME, listw = spdep::nb2listw(COL.nb, style = "B")) summary(jc6)
JoinCount Spatial Tests (asymptotic)
pairs z-value pvalue Joincount Expected Variance
fx - binomial - alternative: greater - Join count test under nonfree sampling
high-high 6.33 0.00000 54 27.22 17.89
low-low 1.01 0.15527 34 29.59 18.90
high-low −6.09 1.00000 28 59.18 26.23