Skip to contents

This 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:

methoda character string giving description of the method.
data.namea character string giving the name(s) of the data.
statisticthe value of the statistic QE or/and QI.
alternativea character string describing the alternative hypothesis.
p.valuep-value for QE or QI.
parameterfree degree of the statistic for QE or QI.
symbA matrix with the symbols.
mhm-surrounding of th map.
Tmnumber of maps (ONLY 2).
sample.sizenumber of symbolized observations.
nska 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ópezfernando.lopez@upct.es
Román Mínguezroman.minguez@uclm.es
Antonio Páezpaezha@gmail.com
Manuel Ruizmanuel.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 = 268.15, 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 = 68.59, df = 81, p-value = 0.8356
#> alternative hypothesis: two.sided
#> 
#> 
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.

plot(qmap, ci=.6)
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.

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 = 286.12, 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 = 228.2, df = 676, p-value = 1
#> alternative hypothesis: two.sided
#> 
#> 
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> 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 = 292.04, 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 = 74.839, df = 81, p-value = 0.6715
#> alternative hypothesis: two.sided
#> 
#> 
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> 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 = 268.15, 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 = 68.59, df = 81, p-value = 0.8356
#> alternative hypothesis: two.sided
#> 
#> 
#> attr(,"class")
#> [1] "qmap" "list"
plot(qmap)
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.


# 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: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> Warning: Use of `data$symb` is discouraged.
#>  Use `symb` instead.
#> 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