Description Usage Arguments Details Value Control arguments Author(s) References Examples
A function to compute Q test for spatial qualitative data
1 2 3 |
formula |
a symbolic description of the factor(s). |
data |
an (optional) data frame or a sf object containing the variable to testing for. |
xf |
input sf object with points/multipolygons geometry or matrix of spatial coordinates. |
coor |
(optional) a 2xN vector with coordinates |
m |
length of m-surrounding (default = 3). |
r |
maximum overlapping between any two m-surroundings (default = 1). |
distr |
character. Distribution type "asymptotic" (default) or "bootstrap". |
control |
Optional argument. See Control Argument section. |
Aquí Antonio escribe una linda historia ....
An object of the class htest
#'
character to select the type of distance. Default = "Euclidean" for Cartesian coordinates only: one of Euclidean, Hausdorff or Frechet; for geodetic coordinates, great circle distances are computed (see sf::st_distance())
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Elimina m-surrounding
number of boots for get the bootstrap distribution. Default = 999
seed to select the initial element to star the algorithm to get compute the m-surroundings or to start the bootstrap
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 |
Ruiz M, López FA, A Páez. (2010). Testing for spatial association of qualitative data using symbolic dynamics. Journal of Geographical Systems. 12 (3) 281-309
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | Case 1: With coordinates
rm(list = ls())
N <- 100
cx <- runif(N)
cy <- runif(N)
coor <- cbind(cx,cy)
p <- c(1/6,3/6,2/6)
rho = 0.5
listw <- spdep::nb2listw(knn2nb(knearneigh(cbind(cx,cy), k = 4)))
xf <- dgp.spq(list = listw, p = p, rho = rho)
q.test <- Q.test(xf = xf, coor = coor, m = 3, r = 1)
summary(q.test)
plot(q.test)
print(q.test)
q.test.boot <- Q.test(xf = xf, coor = coor, m = 3, r = 1, distr = "bootstrap")
summary(q.test.boot)
plot(q.test)
print(q.test)
Case 2: With a sf object
rm(list = ls())
data("FastFood")
f1 <- ~ Type
q.test <- Q.test(formula = f1, data = FastFood.sf, m = 3, r = 1, control = list(distance ="Euclidean"))
summary(q.test)
plot(q.test)
print(q.test)
# Case 3: With a sf object with isolated areas
rm(list = ls())
data("Spain")
f1 <- ~ MenWoman
q.test <- Q.test(formula = f1, data = spain.sf, m = 3, r = 1, control = list(seedinit = 1111))
summary(q.test)
print(q.test)
plot(q.test)
q.test.boot <- Q.test(formula = f1, data = spain.sf, m = 4, r = 3, distr = "bootstrap", control = list(seedinit = 1111))
summary(q.test.boot)
print(q.test.boot)
plot(q.test.boot)
# Case 4: Examples with multipolygons
rm(list = ls())
library(sf)
fname <- system.file("shape/nc.shp", package="sf")
nc <- st_read(fname)
qb79 <- quantile(nc$BIR79)
nc$QBIR79 <- (nc$BIR79 > qb79[2]) + (nc$BIR79 > qb79[3]) +
(nc$BIR79 >= qb79[4]) + 1
nc$QBIR79 <- as.factor(nc$QBIR79)
plot(nc["QBIR79"], pal = c("#FFFEDE","#FFDFA2", "#FFA93F", "#D5610D"),
main = "BIR79 (Quartiles)")
sid79 <- quantile(nc$SID79)
nc$QSID79 <- (nc$SID79 > sid79[2]) + (nc$SID79 > sid79[3]) +
(nc$SID79 >= sid79[4]) + 1
nc$QSID79 <- as.factor(nc$QSID79)
plot(nc["QSID79"], pal = c("#FFFEDE","#FFDFA2", "#FFA93F", "#D5610D"),
main = "SID79 (Quartiles)")
f1 <- ~ QSID79 + QBIR79
lq1nc <- Q.test(formula = f1, data = nc, m = 5, r = 2,
control = list(seedinit = 1111, dtmaxpc = 0.5, distance = "Euclidean") )
print(lq1nc)
lq2nc <- Q.test(formula = f1, data = nc, m = 5, r = 2, control = list(dtmaxpc = 0.2) )
print(lq2nc)
lq3nc <- Q.test(formula = f1, data = nc, m = 5, r = 2, control = list(dtmaxknn = 5) )
print(lq3nc)
# Case 5: Examples with points and matrix of variables
xf <- matrix(c(nc$QBIR79, nc$QSID79), ncol = 2, byrow = TRUE)
mctr <- suppressWarnings(sf::st_centroid(sf::st_geometry(nc)))
mcoor <- sf::st_coordinates(mctr)[,c("X","Y")]
q.test <- Q.test(xf = xf, coor = mcoor, m = 5, r = 2,control = list(seedinit = 1111, dtmaxpc = 0.5))
print(q.test)
plot(q.test)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.