Compute the QE and QI tests of Equivalence and Independence between maps
Source:R/Q.map.test.R
Q.map.test.RdThis function compute the QE and QI tests for maps comparison based on symbolic entropy.
Usage
Q.map.test(formula = formula, data = data, coor = NULL, m = m, r = 1,
type = "combinations", control = list())Arguments
- formula
a symbolic description of the two factors.
- data
(optional) a data frame or a sf object containing the variables to testing for.
- coor
(optional) a 2xN vector with coordinates.
- m
length of m-surrounding.
- r
maximum overlapping between any two m-surroundings (default = 1).
- type
Type of symbols: "permutations" or "combinations". Default "combinations"
- control
Optional argument. See Control Argument section.
Value
A list with two objects of the class htest. The first one
is the QE test of Equivalence between maps and the second one is the QI test
of independence between maps. the elements of each test are:
method | a character string giving description of the method. |
data.name | a character string giving the name(s) of the data. |
statistic | the value of the statistic QE or/and QI. |
alternative | a character string describing the alternative hypothesis. |
p.value | p-value for QE or QI. |
parameter | free degree of the statistic for QE or QI. |
symb | A matrix with the symbols. |
mh | m-surrounding of th map. |
Tm | number of maps (ONLY 2). |
sample.size | number of symbolized observations. |
nsk | a matrix Tm x symbols with the frequency of the number of symbols of each map. |
Details
If data is not a sf object the coor argument with the coordinates
of each observation must be included.
Control arguments
Several parameters to construct the m-surrounding
- dtmaxabs
Delete degenerate surrounding based on the absolute distance between observations.
- dtmaxpc
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.
- dtmaxknn
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
- seedinit
seed to select the initial element to star the algorithm to compute the m-surroundings.
References
Ruiz M, López FA and A Páez (2011). Comparison of Thematic Maps Using Symbolic Entropy. International Journal of Geographical Information Science, 26, 413-439.
Ruiz, M., López, FA, and Páez, A. (2010). Testing for spatial association of qualitative data using symbolic dynamics. Journal of Geographical Systems, 12(3), 281-309.0.
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:
N <- 200
cx <- runif(N)
cy <- runif(N)
x <- cbind(cx,cy)
listw <- spdep::nb2listw(spdep::knn2nb(
spdep::knearneigh(cbind(cx,cy), k = 4)))
p <- c(1/6, 3/6, 2/6)
rho = 0.5
QY1 <- dgp.spq(p = p, listw = listw, rho = rho)
rho = 0.8
QY2 <- dgp.spq(p = p, listw = listw, rho = rho)
dt = data.frame(QY1,QY2)
m = 3
r = 1
formula <- ~ QY1 + QY2
control <- list(dtmaxknn = 10)
qmap <- Q.map.test(formula = formula, data = dt, coor = x, m = m, r = r,
type ="combinations", control = control)
print(qmap)
#> [[1]]
#>
#> Q-Map test of Equivalence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 8.9
#>
#> data: QY1 and QY2
#> QE = 256.93, df = 9, p-value < 2.2e-16
#> alternative hypothesis: two.sided
#>
#>
#> [[2]]
#>
#> Q-Map test of Independence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 8.9
#>
#> data: QY1 and QY2
#> QI = 69.123, df = 81, p-value = 0.8238
#> alternative hypothesis: two.sided
#>
#>
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
plot(qmap, ci=.6)
plot(qmap[[1]]$mh)
summary(qmap[[1]]$mh)
#>
#> Characteristics of m-surrounding:
#>
#> Number of m-surrounding (R): 89
#> Length of m-surrounding (m): 3
#> Number no-symbolized observations: 14
#>
#> List of no-symbolized observations:
#> 13 16 19 31 43 65 72 77 105 121 166 182 198 200
#>
#> List of the degree overlaping:
#> There are 2 m-surrounding that have intersection with 0 m-surrounding
#> There are 12 m-surrounding that have intersection with 1 m-surrounding
#> There are 75 m-surrounding that have intersection with 2 m-surrounding
#> Mean degree of overlaping: 1.8202
control <- list(dtmaxknn = 20)
qmap <- Q.map.test(formula = formula, data = dt, coor = x, m = m, r = r,
type ="permutations", control = control)
#> Warning: The ratio between the number of symbolized observations and the number of symbols is lower than 5.
print(qmap)
#> [[1]]
#>
#> Q-Map test of Equivalence for qualitative data.
#>
#> Symbols type: permutations
#>
#> Ratio Symbolized observations/Num symbols = 3.48
#>
#> data: QY1 and QY2
#> QE = 287.02, df = 26, p-value < 2.2e-16
#> alternative hypothesis: two.sided
#>
#>
#> [[2]]
#>
#> Q-Map test of Independence for qualitative data.
#>
#> Symbols type: permutations
#>
#> Ratio Symbolized observations/Num symbols = 3.48
#>
#> data: QY1 and QY2
#> QI = 235.11, df = 676, p-value = 1
#> alternative hypothesis: two.sided
#>
#>
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
plot(qmap[[1]]$mh)
qmap <- Q.map.test(formula = formula, data = dt, coor = x, m = m, r = r,
type ="combinations")
print(qmap)
#> [[1]]
#>
#> Q-Map test of Equivalence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 9.9
#>
#> data: QY1 and QY2
#> QE = 285.58, df = 9, p-value < 2.2e-16
#> alternative hypothesis: two.sided
#>
#>
#> [[2]]
#>
#> Q-Map test of Independence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 9.9
#>
#> data: QY1 and QY2
#> QI = 68.477, df = 81, p-value = 0.8381
#> alternative hypothesis: two.sided
#>
#>
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
control <- list(dtmaxknn = 10)
qmap <- Q.map.test(formula = formula, data = dt, coor = x, m = m, r = r,
type ="combinations", control = control)
print(qmap)
#> [[1]]
#>
#> Q-Map test of Equivalence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 8.9
#>
#> data: QY1 and QY2
#> QE = 256.93, df = 9, p-value < 2.2e-16
#> alternative hypothesis: two.sided
#>
#>
#> [[2]]
#>
#> Q-Map test of Independence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 8.9
#>
#> data: QY1 and QY2
#> QI = 69.123, df = 81, p-value = 0.8238
#> alternative hypothesis: two.sided
#>
#>
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
# Case 2:
data(provinces_spain)
# sf::sf_use_s2(FALSE)
m = 3
r = 1
provinces_spain$Mal2Fml <- factor(provinces_spain$Mal2Fml > 100)
levels(provinces_spain$Mal2Fml) = c("men","woman")
provinces_spain$Coast <- factor(provinces_spain$Coast)
levels(provinces_spain$Coast) = c("no","yes")
formula <- ~ Coast + Mal2Fml
qmap <- Q.map.test(formula = formula, data = provinces_spain, m = m, r = r,
type ="combinations")
print(qmap)
#> [[1]]
#>
#> Q-Map test of Equivalence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 6
#>
#> data: Coast and Mal2Fml
#> QE = 71.83, df = 3, p-value = 1.731e-15
#> alternative hypothesis: two.sided
#>
#>
#> [[2]]
#>
#> Q-Map test of Independence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 6
#>
#> data: Coast and Mal2Fml
#> QI = 7.5057, df = 9, p-value = 0.5846
#> alternative hypothesis: two.sided
#>
#>
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
plot(qmap[[1]]$mh)
control <- list(dtmaxknn = 6)
qmap <- Q.map.test(formula = formula, data = provinces_spain, m = m, r = r,
type ="combinations", control = control)
print(qmap)
#> [[1]]
#>
#> Q-Map test of Equivalence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 5
#>
#> data: Coast and Mal2Fml
#> QE = 58.615, df = 3, p-value = 1.162e-12
#> alternative hypothesis: two.sided
#>
#>
#> [[2]]
#>
#> Q-Map test of Independence for qualitative data.
#>
#> Symbols type: combinations
#>
#> Ratio Symbolized observations/Num symbols = 5
#>
#> data: Coast and Mal2Fml
#> QI = 7.1454, df = 9, p-value = 0.622
#> alternative hypothesis: two.sided
#>
#>
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap[[1]]$mh)
summary(qmap[[1]]$mh)
#>
#> Characteristics of m-surrounding:
#>
#> Number of m-surrounding (R): 20
#> Length of m-surrounding (m): 3
#> Number no-symbolized observations: 8
#>
#> List of no-symbolized observations:
#> 7 13 19 20 34 35 37 48
#>
#> List of the degree overlaping:
#> There are 4 m-surrounding that have intersection with 1 m-surrounding
#> There are 16 m-surrounding that have intersection with 2 m-surrounding
#> Mean degree of overlaping: 1.8