A function to compute joint-count test for binomial and multinomial (asymptotic and permutation distributions).
Source:R/jc.test.R
jc.test.Rd
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 bynb2listw
from spdep package; ifnb2listw
not given, the spatial weights are built using the object given inlistw
argument (usually ansf
object). Default =NULL
.- na.action
A function (default
options("na.action")
), can also bena.omit
orna.exclude
. It may be necessary to setzero.policy
toTRUE
because this subsetting may create no-neighbour observations.- zero.policy
Similar to the corresponding parameter of
lagsarlm
function in spatialreg package. IfTRUE
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
nsim | number of permutations used in
the Monte Carlo distribution.
Default nsim = 999. |
seedinit | seed to select the initial
element during the simulations.
Default seedinit = 1111. |
adjust.n | default 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. |
spChk | should 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. |
sampling | default nonfree,
may be free.
See joincount.test for
additional information. |
queen | default TRUE. Defines the neighborhood criteria for sf objects. |
style | defines the style for
listw . Default = B (binary). |
knn | chooses 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ópez | fernando.lopez@upct.es |
Román Mínguez | roman.minguez@uclm.es |
Antonio Páez | paezha@gmail.com |
Manuel Ruiz | manuel.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)
Mal2Fml - binomial - alternative: greater - Monte-Carlo simulation of join-count statistic
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
Coast - binomial - alternative: greater - Monte-Carlo simulation of join-count statistic
# }
# 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
# 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
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
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