Description Usage Arguments Details Value Control arguments Author(s) References Examples
A function to compute Q test for spatial qualitative data
1 2 3 4 5 6 |
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 |
coor |
(optional) a 2xN vector with spatial coordinates. Used when data is not a spatial object |
m |
length of m-surrounding (default = 3). |
r |
maximum overlapping between any two m-surroundings (default = 1). |
distr |
character. Distribution type "asymptotic" (default) or "mc". |
control |
Optional argument. See Control Argument section. |
Aquí Antonio escribe una linda historia ....
An list of two object of the class htest
. Each element of the list return the:
data.name | a character string giving the names of the data. |
statistic | Value of the Q test |
N | total number of observations. |
R | total number of simbolized observations. |
m | length m-surrounding. |
r | degree of overlapping. |
df | degree of freedom. |
distr | type of distribution used to get the significance of the Q test. |
type | type of simbols. |
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())
Delete degenerate surrounding based on the absolute distance between observations.
A value between 0 and 1. Delete degenerate surrounding based on the distance. Delete m-surrounding when the maximum distance between observation is upper than k percentage of maximum distance between anywhere observation.
A integer value 'k'. Delete degenerate surrounding based on the near neighborhood criteria. Delete m-surrounding is a element of the m-surrounding is not include in the set of k near neighborhood of the first element
number of simulations for get the Monte Carlo distribution. Default = 999
seed to select the initial element to star the algorithm to get compute the m-surroundings or to start the simulation
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 75 76 | # 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)))
fx <- dgp.spq(list = listw, p = p, rho = rho)
q.test <- Q.test(fx = fx, coor = coor, m = 3, r = 1)
summary(q.test)
plot(q.test)
print(q.test)
q.test.mc <- Q.test(fx = fx, coor = coor, m = 3, r = 1, distr = "mc")
summary(q.test.mc)
plot(q.test.mc)
print(q.test.mc)
# Case 2: With a sf object
rm(list = ls())
data("FastFood")
f1 <- ~ Type
q.test <- Q.test(formula = f1, data = FastFood.sf, m = c(3, 4),
r = c(1, 2, 3), 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 <- ~ Older65 + 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.mc <- Q.test(formula = f1, data = spain.sf, m = 4, r = 3, distr = "mc", control = list(seedinit = 1111))
summary(q.test.mc)
print(q.test.mc)
plot(q.test.mc)
# 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
fx <- 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(fx = fx, 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.