Skip to contents

A function to compute Q test for spatial qualitative data.

Usage

Q.test(formula = NULL, data = NULL, na.action,
fx = NULL, coor = NULL, m = 3, r = 1, distr = "asymptotic",
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.

na.action

action with NA values

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

only for asimtotic distribution. Maximum overlapping between any two m-surroundings (default = 1).

distr

character. Distribution type "asymptotic" (default) or "mc".

control

Optional argument. See Control Argument section.

Value

An list of two object of the class htest. Each element of the list return the:

data.namea character string giving the names of the data.
statisticValue of the Q test
Ntotal number of observations.
Rtotal number of symbolized observations.
mlength m-surrounding.
rdegree of overlapping.
dfdegree of freedom.
distrtype of distribution used to get the significance of the Q test.
typetype of symbols.

Details

The Q-test is a simple, consistent, and powerful statistic for qualitative spatial independence that we develop using concepts from symbolic dynamics and symbolic entropy. The Q test can be used to detect, given a spatial distribution of events, patterns of spatial association of qualitative variables in a wide variety of settings.
The Q(m) statistic was introduced by Ruiz et al. (2010) as a tool to explore geographical co-location/co-occurrence of qualitative data. Consider a spatial variable X which is the result of a qualitative process with a set number of categorical outcomes \(a_j\) (j=1,...,k). The spatial variable is observed at a set of fixed locations indexed by their coordinates \(s_i\) (i=1,..., N), so that at each location si where an event is observed, \(X_i\) takes one of the possible values \(a_j\).

Since the observations are georeferenced, a spatial embedding protocol can be devised to assess the spatial property of co-location. Let us define, for an observation at a specified location, say \(s_0\), a surrounding of size m, called an m-surrounding.
The m-surrounding is the set of m-1 nearest neighbours from the perspective of location \(s_0\). In the case of distance ties, a secondary criterion can be invoked based on direction.
Once that an embedding protocol is adopted and the elements of the m-surrounding for location \(s_0\) have been determined, a string can be obtained that collects the elements of the local neighborhood (the m-1 nearest neighbors) of the observation at \(s_0\). The m-surrounding can then be represented in the following way:

$$X_m(s_0)=(X_{s_0},X_{s_1},...X_{s_{m-1}})$$ Since each observation Xs takes one of k possible values, and there are m observations in the m-surrounding, there are exactly k possible unique ways in which those values can co-locate. This is the number of permutations with replacement.
For instance, if k=2 (e.g. the possible outcomes are a1=0 and a2=1) and m=3, the following eight unique patterns of co-location are possible (the number of symbols is \(n_{\sigma}\)=8): 0,0,0, 1,0,0, 0,1,0, 0,0,1, 1,1,0, 1,0,1, 0,1,1, and 1,1,1. Each unique co-locationtype can be denoted in a convenient way by means of a symbol \(\sigma_i\) \((i=1, 2,...,k^m)\). It follows that each site can be uniquely associated with a specific symbol, in a process termed symbolization. In this way, we say that a location s is of type \(\sigma_i\) if and only if \(X_m(s)=\sigma_i\).
Equivalent symbols (see Páez, et al. 2012) can be obtained by counting the number of occurrences of each category within an m-surrounding. This surrenders some topological information (ordering within the m-surrounding is lost) in favor of a more compact set of symbols, since the number of combinations with replacement.

Definition of Q(m) statistic

Let \(\{X_s\}_{s \in R}\) be a discrete spatial process and m be a fixed embedding dimension. The statistic Q testing the null hypothesis:

\(H_0:\{X_s\}_{s \in R}\) is spatially independent, against any other alternative.

For a fixed \(m \geq 2\), the relative frequency of symbols can be used to define the symbolic entropy of the spatial process as the Shanon entropy of the distinct symbols:
$$h(m) = - \sum_j p_{\sigma_j}ln(p_{\sigma_j})$$ where $$p_{\sigma_j}={ n_{\sigma_j} \over R}$$ with \(n_{\sigma_j}\) is simply the number of times that the symbol \(\sigma_j\) is observed and R the number of symbolized locations. The entropy function is bounded between \(0 < h (m) \leq \eta\).

The Q statistic is essentially a likelihood ratio test between the symbolic entropy of the observed pattern and the entropy of the system under the null hypothesis of a random spatial sequence: $$Q(m)=2R(\eta-h(m))$$ with \(\eta = ln(k^m)\). The statistic is asymptotically \(\chi^2\) distributed with degrees of freedom equal to the number of symbols minus one.

Control arguments

distance

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())

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 neighbourhood criteria. Delete m-surrounding is a element of the m-surrounding is not include in the set of k near neighbourhood of the first element

nsim

number of simulations for get the Monte Carlo distribution. Default = 999

seedinit

seed to select the initial element to star the algorithm to get compute the m-surroundings or to start the simulation

Standard-Permutation vs Equivalent-Combination Symbols

The symbolization protocol proposed by Ruiz et al. (2010) - call these Standard-Permutation Symbols — contains a large amount of topological information regarding the units of analysis, including proximity and direction. In this sense, the protocol is fairly general. On the other hand, it is easy to see that the combinatorial possibilities can very quickly become unmanageable. For a process with k = 3 outcomes and m = 5, the number of symbols becomes \(3^5 = 243\); for k = 6 and m = 4 it is \(6^4 = 1,296\). Depending on the number of observations N, the explosion in the number of symbols can very rapidly consume degrees of freedom for hypothesis testing, because as a rule of thumb it is recommended that the number of symbolized locations be at least five times the number of symbols used (e.g., \(R \geq 5k^m\)), and R will usually be a fraction of N.

As an alternative, we propose a symbolization protocol that sacrifices some amount of topological detail for conciseness. The alternative is based on the standard scheme; however, instead of retaining proximity and direction relationships, it maintains only the total number of occurrences of each outcome in an m-surrounding. We call these Equivalent-Combination Symbols. Because order in the sequence is not considered in this protocol, instead of a permutation with repetition, the number of symbols reflects a combination with repetition.

Selection of m-surrounding with Controlled Degree of Overlapping (r)

To select S locations for the analysis, coordinates are selected such that for any two coordinates \(s_i\) , \(s_j\) the number of overlapping nearest neighbours of \(s_i\) and \(s_j\) are at most r. The set S, which is a subset of all the observations N, is defined recursively as follows. First choose a location \(s_0\) at random and fix an integer r with \(0 \leq r < m\). The integer r is the degree of overlap, the maximum number of observations that contiguous m-surroundings are allowed to have in common.
Let \( \{s_1^0, s_2^0,...,s_{m-1}^0 \}\) be the set of nearest neighbours to \(s_0\), where the \(s_i^0\) are ordered by distance to \(s_0\), or angle in the case of ties. Let us call \(s_1 = s_{m-r-1}^0\) and define \( A_0 = \{s_0,s_0^1,...,s^0_{m-r-2} \} \) . Take the set of nearest neighbours to \(s_1\), namely, \( \{ s_1^1, s_2^1,...,s^1_{m-1} \} \) in the set of locations \(S \setminus A_0 \) and define \(s_2=s^1_{m-r-1} \). Nor for i>1 we define \(s_i = s^{i-1}_{m-r-1}\) where \(s^{i-1}_{m-r-1}\) is in the ser of nearest neighbors to \(s_{i-1}\), \( \{ s_1^{i-1},s_2^{i-1},...,s_{m-1}^{i-1} \} \) ,of the set \(S \setminus \{ \cup_{j=0}^{i-1} A_j \} \). Continue this process while there are locations to symbolize.

Selection of m-surroundings for bootstrap distribution

The bootstrapped-based testing can provide an advantage since overlapping between m-surroundings is not a consideration, and the full sample can be used.

References

  • 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

  • López, FA, and A Páez. (2012). Distribution-free inference for Q(m) based on permutational bootstrapping: an application to the spatial co-location pattern of firms in Madrid Estadística Española, 177, 135-156.

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: With coordinates
N <- 200
cx <- runif(N)
cy <- runif(N)
coor <- cbind(cx,cy)
p <- c(1/6,3/6,2/6)
rho = 0.3
listw <- spdep::nb2listw(spdep::knn2nb(spdep::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)
#> <div id="vrzdqffzog" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
#>   <style>html {
#>   font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
#> }
#> 
#> #vrzdqffzog .gt_table {
#>   display: table;
#>   border-collapse: collapse;
#>   margin-left: auto;
#>   margin-right: auto;
#>   color: #333333;
#>   font-size: 16px;
#>   font-weight: normal;
#>   font-style: normal;
#>   background-color: #FFFFFF;
#>   width: auto;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #A8A8A8;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #A8A8A8;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_heading {
#>   background-color: #FFFFFF;
#>   text-align: center;
#>   border-bottom-color: #FFFFFF;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_title {
#>   color: #333333;
#>   font-size: 125%;
#>   font-weight: initial;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-color: #FFFFFF;
#>   border-bottom-width: 0;
#> }
#> 
#> #vrzdqffzog .gt_subtitle {
#>   color: #333333;
#>   font-size: 85%;
#>   font-weight: initial;
#>   padding-top: 0;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-color: #FFFFFF;
#>   border-top-width: 0;
#> }
#> 
#> #vrzdqffzog .gt_bottom_border {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_col_headings {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_col_heading {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   overflow-x: hidden;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   padding-top: 0;
#>   padding-bottom: 0;
#>   padding-left: 4px;
#>   padding-right: 4px;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer:first-child {
#>   padding-left: 0;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer:last-child {
#>   padding-right: 0;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 5px;
#>   overflow-x: hidden;
#>   display: inline-block;
#>   width: 100%;
#> }
#> 
#> #vrzdqffzog .gt_group_heading {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #vrzdqffzog .gt_empty_group_heading {
#>   padding: 0.5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #vrzdqffzog .gt_from_md > :first-child {
#>   margin-top: 0;
#> }
#> 
#> #vrzdqffzog .gt_from_md > :last-child {
#>   margin-bottom: 0;
#> }
#> 
#> #vrzdqffzog .gt_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   margin: 10px;
#>   border-top-style: solid;
#>   border-top-width: 1px;
#>   border-top-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#>   overflow-x: hidden;
#> }
#> 
#> #vrzdqffzog .gt_stub {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_stub_row_group {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   vertical-align: top;
#> }
#> 
#> #vrzdqffzog .gt_row_group_first td {
#>   border-top-width: 2px;
#> }
#> 
#> #vrzdqffzog .gt_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_first_summary_row {
#>   border-top-style: solid;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_first_summary_row.thick {
#>   border-top-width: 2px;
#> }
#> 
#> #vrzdqffzog .gt_last_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_grand_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_first_grand_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-style: double;
#>   border-top-width: 6px;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_striped {
#>   background-color: rgba(128, 128, 128, 0.05);
#> }
#> 
#> #vrzdqffzog .gt_table_body {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_footnotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_footnote {
#>   margin: 0px;
#>   font-size: 90%;
#>   padding-left: 4px;
#>   padding-right: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_sourcenotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_sourcenote {
#>   font-size: 90%;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_left {
#>   text-align: left;
#> }
#> 
#> #vrzdqffzog .gt_center {
#>   text-align: center;
#> }
#> 
#> #vrzdqffzog .gt_right {
#>   text-align: right;
#>   font-variant-numeric: tabular-nums;
#> }
#> 
#> #vrzdqffzog .gt_font_normal {
#>   font-weight: normal;
#> }
#> 
#> #vrzdqffzog .gt_font_bold {
#>   font-weight: bold;
#> }
#> 
#> #vrzdqffzog .gt_font_italic {
#>   font-style: italic;
#> }
#> 
#> #vrzdqffzog .gt_super {
#>   font-size: 65%;
#> }
#> 
#> #vrzdqffzog .gt_footnote_marks {
#>   font-style: italic;
#>   font-weight: normal;
#>   font-size: 75%;
#>   vertical-align: 0.4em;
#> }
#> 
#> #vrzdqffzog .gt_asterisk {
#>   font-size: 100%;
#>   vertical-align: 0;
#> }
#> 
#> #vrzdqffzog .gt_slash_mark {
#>   font-size: 0.7em;
#>   line-height: 0.7em;
#>   vertical-align: 0.15em;
#> }
#> 
#> #vrzdqffzog .gt_fraction_numerator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: 0.45em;
#> }
#> 
#> #vrzdqffzog .gt_fraction_denominator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: -0.05em;
#> }
#> </style>
#>   <table class="gt_table">
#>   <thead class="gt_header">
#>     <tr>
#>       <th colspan="11" class="gt_heading gt_title gt_font_normal" style>Qualitative Dependence Test (Q)</th>
#>     </tr>
#>     <tr>
#>       <th colspan="11" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border" style>Distribution: asymptotic. Distance: Euclidean</th>
#>     </tr>
#>   </thead>
#>   <thead class="gt_col_headings">
#>     <tr>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">Q</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">df</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">p.value</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">k</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">N</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">m</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">r</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R/n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">5k^m</th>
#>     </tr>
#>   </thead>
#>   <tbody class="gt_table_body">
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">V1 - standard-permutations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">23.58</td>
#> <td class="gt_row gt_right">26</td>
#> <td class="gt_row gt_right">0.59974</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">200</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">99</td>
#> <td class="gt_row gt_right">27</td>
#> <td class="gt_row gt_right">3.67</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">V1 - equivalent-combinations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">7.78</td>
#> <td class="gt_row gt_right">9</td>
#> <td class="gt_row gt_right">0.55682</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">200</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">99</td>
#> <td class="gt_row gt_right">10</td>
#> <td class="gt_row gt_right">9.90</td>
#> <td class="gt_row gt_right">135</td></tr>
#>   </tbody>
#>   
#>   
#> </table>
#> </div>
plot(q.test)
#> [[1]]

#> 
#> [[2]]

#> 
print(q.test)
#> [[1]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable V1  m =  3  r =  1
#> Qp = 23.584, df = 26, p-value = 0.5997
#> 
#> 
#> [[2]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable V1  m =  3  r =  1
#> Qc = 7.7765, df = 9, p-value = 0.5568
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   
# \donttest{
q.test.mc <- Q.test(fx = fx, coor = coor, m = 3, distr = "mc", control = list(nsim = 999))
summary(q.test.mc)
#> <div id="hclvlliyhf" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
#>   <style>html {
#>   font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
#> }
#> 
#> #hclvlliyhf .gt_table {
#>   display: table;
#>   border-collapse: collapse;
#>   margin-left: auto;
#>   margin-right: auto;
#>   color: #333333;
#>   font-size: 16px;
#>   font-weight: normal;
#>   font-style: normal;
#>   background-color: #FFFFFF;
#>   width: auto;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #A8A8A8;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #A8A8A8;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_heading {
#>   background-color: #FFFFFF;
#>   text-align: center;
#>   border-bottom-color: #FFFFFF;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_title {
#>   color: #333333;
#>   font-size: 125%;
#>   font-weight: initial;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-color: #FFFFFF;
#>   border-bottom-width: 0;
#> }
#> 
#> #hclvlliyhf .gt_subtitle {
#>   color: #333333;
#>   font-size: 85%;
#>   font-weight: initial;
#>   padding-top: 0;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-color: #FFFFFF;
#>   border-top-width: 0;
#> }
#> 
#> #hclvlliyhf .gt_bottom_border {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_col_headings {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_col_heading {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   overflow-x: hidden;
#> }
#> 
#> #hclvlliyhf .gt_column_spanner_outer {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   padding-top: 0;
#>   padding-bottom: 0;
#>   padding-left: 4px;
#>   padding-right: 4px;
#> }
#> 
#> #hclvlliyhf .gt_column_spanner_outer:first-child {
#>   padding-left: 0;
#> }
#> 
#> #hclvlliyhf .gt_column_spanner_outer:last-child {
#>   padding-right: 0;
#> }
#> 
#> #hclvlliyhf .gt_column_spanner {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 5px;
#>   overflow-x: hidden;
#>   display: inline-block;
#>   width: 100%;
#> }
#> 
#> #hclvlliyhf .gt_group_heading {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #hclvlliyhf .gt_empty_group_heading {
#>   padding: 0.5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #hclvlliyhf .gt_from_md > :first-child {
#>   margin-top: 0;
#> }
#> 
#> #hclvlliyhf .gt_from_md > :last-child {
#>   margin-bottom: 0;
#> }
#> 
#> #hclvlliyhf .gt_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   margin: 10px;
#>   border-top-style: solid;
#>   border-top-width: 1px;
#>   border-top-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#>   overflow-x: hidden;
#> }
#> 
#> #hclvlliyhf .gt_stub {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #hclvlliyhf .gt_stub_row_group {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   vertical-align: top;
#> }
#> 
#> #hclvlliyhf .gt_row_group_first td {
#>   border-top-width: 2px;
#> }
#> 
#> #hclvlliyhf .gt_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #hclvlliyhf .gt_first_summary_row {
#>   border-top-style: solid;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_first_summary_row.thick {
#>   border-top-width: 2px;
#> }
#> 
#> #hclvlliyhf .gt_last_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_grand_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #hclvlliyhf .gt_first_grand_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-style: double;
#>   border-top-width: 6px;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_striped {
#>   background-color: rgba(128, 128, 128, 0.05);
#> }
#> 
#> #hclvlliyhf .gt_table_body {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_footnotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_footnote {
#>   margin: 0px;
#>   font-size: 90%;
#>   padding-left: 4px;
#>   padding-right: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #hclvlliyhf .gt_sourcenotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #hclvlliyhf .gt_sourcenote {
#>   font-size: 90%;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #hclvlliyhf .gt_left {
#>   text-align: left;
#> }
#> 
#> #hclvlliyhf .gt_center {
#>   text-align: center;
#> }
#> 
#> #hclvlliyhf .gt_right {
#>   text-align: right;
#>   font-variant-numeric: tabular-nums;
#> }
#> 
#> #hclvlliyhf .gt_font_normal {
#>   font-weight: normal;
#> }
#> 
#> #hclvlliyhf .gt_font_bold {
#>   font-weight: bold;
#> }
#> 
#> #hclvlliyhf .gt_font_italic {
#>   font-style: italic;
#> }
#> 
#> #hclvlliyhf .gt_super {
#>   font-size: 65%;
#> }
#> 
#> #hclvlliyhf .gt_footnote_marks {
#>   font-style: italic;
#>   font-weight: normal;
#>   font-size: 75%;
#>   vertical-align: 0.4em;
#> }
#> 
#> #hclvlliyhf .gt_asterisk {
#>   font-size: 100%;
#>   vertical-align: 0;
#> }
#> 
#> #hclvlliyhf .gt_slash_mark {
#>   font-size: 0.7em;
#>   line-height: 0.7em;
#>   vertical-align: 0.15em;
#> }
#> 
#> #hclvlliyhf .gt_fraction_numerator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: 0.45em;
#> }
#> 
#> #hclvlliyhf .gt_fraction_denominator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: -0.05em;
#> }
#> </style>
#>   <table class="gt_table">
#>   <thead class="gt_header">
#>     <tr>
#>       <th colspan="9" class="gt_heading gt_title gt_font_normal" style>Qualitative Dependence Test (Q)</th>
#>     </tr>
#>     <tr>
#>       <th colspan="9" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border" style>Distribution: mc. Distance: Euclidean</th>
#>     </tr>
#>   </thead>
#>   <thead class="gt_col_headings">
#>     <tr>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">Q</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">p.value</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">k</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">N</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">m</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R/n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">5k^m</th>
#>     </tr>
#>   </thead>
#>   <tbody class="gt_table_body">
#>     <tr class="gt_group_heading_row">
#>       <td colspan="9" class="gt_group_heading">V1 - standard-permutations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">42.76</td>
#> <td class="gt_row gt_right">0.08900</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">200</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">200</td>
#> <td class="gt_row gt_right">27</td>
#> <td class="gt_row gt_right">7.41</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="9" class="gt_group_heading">V1 - equivalent-combinations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">27.92</td>
#> <td class="gt_row gt_right">0.04800</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">200</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">200</td>
#> <td class="gt_row gt_right">10</td>
#> <td class="gt_row gt_right">20.00</td>
#> <td class="gt_row gt_right">135</td></tr>
#>   </tbody>
#>   
#>   
#> </table>
#> </div>
plot(q.test.mc)
#> [[1]]

#> 
#> [[2]]

#> 
print(q.test.mc)
#> [[1]]
#> 
#> 	Qp (mc distrib.) for symbolization based on permutations
#> 
#> data:  Variable V1  m =  3  r =  2
#> Qp = 42.765, df = NA, p-value = 0.089
#> 
#> 
#> [[2]]
#> 
#> 	Qc (mc distrib.) for symbolization based on combinations
#> 
#> data:  Variable V1  m =  3  r =  2
#> Qc = 27.921, df = NA, p-value = 0.048
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   


# Case 2: With a sf object
data("FastFood.sf")
f1 <- ~ Type
q.test <- Q.test(formula = f1, data = FastFood.sf, m = c(3, 4),
r = c(1, 2, 3), control = list(distance ="Euclidean"))
#> Warning: bounding box has potentially an invalid value range for longlat data
#> Warning: bounding box has potentially an invalid value range for longlat data
#> Warning: bounding box has potentially an invalid value range for longlat data
#> Warning: bounding box has potentially an invalid value range for longlat data
#> Warning: bounding box has potentially an invalid value range for longlat data
summary(q.test)
#> <div id="vrzdqffzog" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
#>   <style>html {
#>   font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
#> }
#> 
#> #vrzdqffzog .gt_table {
#>   display: table;
#>   border-collapse: collapse;
#>   margin-left: auto;
#>   margin-right: auto;
#>   color: #333333;
#>   font-size: 16px;
#>   font-weight: normal;
#>   font-style: normal;
#>   background-color: #FFFFFF;
#>   width: auto;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #A8A8A8;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #A8A8A8;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_heading {
#>   background-color: #FFFFFF;
#>   text-align: center;
#>   border-bottom-color: #FFFFFF;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_title {
#>   color: #333333;
#>   font-size: 125%;
#>   font-weight: initial;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-color: #FFFFFF;
#>   border-bottom-width: 0;
#> }
#> 
#> #vrzdqffzog .gt_subtitle {
#>   color: #333333;
#>   font-size: 85%;
#>   font-weight: initial;
#>   padding-top: 0;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-color: #FFFFFF;
#>   border-top-width: 0;
#> }
#> 
#> #vrzdqffzog .gt_bottom_border {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_col_headings {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_col_heading {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   overflow-x: hidden;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   padding-top: 0;
#>   padding-bottom: 0;
#>   padding-left: 4px;
#>   padding-right: 4px;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer:first-child {
#>   padding-left: 0;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer:last-child {
#>   padding-right: 0;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 5px;
#>   overflow-x: hidden;
#>   display: inline-block;
#>   width: 100%;
#> }
#> 
#> #vrzdqffzog .gt_group_heading {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #vrzdqffzog .gt_empty_group_heading {
#>   padding: 0.5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #vrzdqffzog .gt_from_md > :first-child {
#>   margin-top: 0;
#> }
#> 
#> #vrzdqffzog .gt_from_md > :last-child {
#>   margin-bottom: 0;
#> }
#> 
#> #vrzdqffzog .gt_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   margin: 10px;
#>   border-top-style: solid;
#>   border-top-width: 1px;
#>   border-top-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#>   overflow-x: hidden;
#> }
#> 
#> #vrzdqffzog .gt_stub {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_stub_row_group {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   vertical-align: top;
#> }
#> 
#> #vrzdqffzog .gt_row_group_first td {
#>   border-top-width: 2px;
#> }
#> 
#> #vrzdqffzog .gt_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_first_summary_row {
#>   border-top-style: solid;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_first_summary_row.thick {
#>   border-top-width: 2px;
#> }
#> 
#> #vrzdqffzog .gt_last_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_grand_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_first_grand_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-style: double;
#>   border-top-width: 6px;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_striped {
#>   background-color: rgba(128, 128, 128, 0.05);
#> }
#> 
#> #vrzdqffzog .gt_table_body {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_footnotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_footnote {
#>   margin: 0px;
#>   font-size: 90%;
#>   padding-left: 4px;
#>   padding-right: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_sourcenotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_sourcenote {
#>   font-size: 90%;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_left {
#>   text-align: left;
#> }
#> 
#> #vrzdqffzog .gt_center {
#>   text-align: center;
#> }
#> 
#> #vrzdqffzog .gt_right {
#>   text-align: right;
#>   font-variant-numeric: tabular-nums;
#> }
#> 
#> #vrzdqffzog .gt_font_normal {
#>   font-weight: normal;
#> }
#> 
#> #vrzdqffzog .gt_font_bold {
#>   font-weight: bold;
#> }
#> 
#> #vrzdqffzog .gt_font_italic {
#>   font-style: italic;
#> }
#> 
#> #vrzdqffzog .gt_super {
#>   font-size: 65%;
#> }
#> 
#> #vrzdqffzog .gt_footnote_marks {
#>   font-style: italic;
#>   font-weight: normal;
#>   font-size: 75%;
#>   vertical-align: 0.4em;
#> }
#> 
#> #vrzdqffzog .gt_asterisk {
#>   font-size: 100%;
#>   vertical-align: 0;
#> }
#> 
#> #vrzdqffzog .gt_slash_mark {
#>   font-size: 0.7em;
#>   line-height: 0.7em;
#>   vertical-align: 0.15em;
#> }
#> 
#> #vrzdqffzog .gt_fraction_numerator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: 0.45em;
#> }
#> 
#> #vrzdqffzog .gt_fraction_denominator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: -0.05em;
#> }
#> </style>
#>   <table class="gt_table">
#>   <thead class="gt_header">
#>     <tr>
#>       <th colspan="11" class="gt_heading gt_title gt_font_normal" style>Qualitative Dependence Test (Q)</th>
#>     </tr>
#>     <tr>
#>       <th colspan="11" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border" style>Distribution: asymptotic. Distance: Euclidean</th>
#>     </tr>
#>   </thead>
#>   <thead class="gt_col_headings">
#>     <tr>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">Q</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">df</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">p.value</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">k</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">N</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">m</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">r</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R/n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">5k^m</th>
#>     </tr>
#>   </thead>
#>   <tbody class="gt_table_body">
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">Type - standard-permutations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">40.10</td>
#> <td class="gt_row gt_right">26</td>
#> <td class="gt_row gt_right">0.03812</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">438</td>
#> <td class="gt_row gt_right">27</td>
#> <td class="gt_row gt_right">16.22</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr><td class="gt_row gt_right">71.71</td>
#> <td class="gt_row gt_right">26</td>
#> <td class="gt_row gt_right">0.00000</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">875</td>
#> <td class="gt_row gt_right">27</td>
#> <td class="gt_row gt_right">32.41</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr><td class="gt_row gt_right">89.02</td>
#> <td class="gt_row gt_right">80</td>
#> <td class="gt_row gt_right">0.22966</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">292</td>
#> <td class="gt_row gt_right">81</td>
#> <td class="gt_row gt_right">3.60</td>
#> <td class="gt_row gt_right">405</td></tr>
#>     <tr><td class="gt_row gt_right">115.69</td>
#> <td class="gt_row gt_right">80</td>
#> <td class="gt_row gt_right">0.00559</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">437</td>
#> <td class="gt_row gt_right">81</td>
#> <td class="gt_row gt_right">5.40</td>
#> <td class="gt_row gt_right">405</td></tr>
#>     <tr><td class="gt_row gt_right">151.65</td>
#> <td class="gt_row gt_right">80</td>
#> <td class="gt_row gt_right">0.00000</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">874</td>
#> <td class="gt_row gt_right">81</td>
#> <td class="gt_row gt_right">10.79</td>
#> <td class="gt_row gt_right">405</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">Type - equivalent-combinations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">26.51</td>
#> <td class="gt_row gt_right">9</td>
#> <td class="gt_row gt_right">0.00169</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">438</td>
#> <td class="gt_row gt_right">10</td>
#> <td class="gt_row gt_right">43.80</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr><td class="gt_row gt_right">64.67</td>
#> <td class="gt_row gt_right">9</td>
#> <td class="gt_row gt_right">0.00000</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">875</td>
#> <td class="gt_row gt_right">10</td>
#> <td class="gt_row gt_right">87.50</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr><td class="gt_row gt_right">28.83</td>
#> <td class="gt_row gt_right">14</td>
#> <td class="gt_row gt_right">0.01102</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">292</td>
#> <td class="gt_row gt_right">15</td>
#> <td class="gt_row gt_right">19.47</td>
#> <td class="gt_row gt_right">405</td></tr>
#>     <tr><td class="gt_row gt_right">44.19</td>
#> <td class="gt_row gt_right">14</td>
#> <td class="gt_row gt_right">0.00006</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">437</td>
#> <td class="gt_row gt_right">15</td>
#> <td class="gt_row gt_right">29.13</td>
#> <td class="gt_row gt_right">405</td></tr>
#>     <tr><td class="gt_row gt_right">81.26</td>
#> <td class="gt_row gt_right">14</td>
#> <td class="gt_row gt_right">0.00000</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">877</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">874</td>
#> <td class="gt_row gt_right">15</td>
#> <td class="gt_row gt_right">58.27</td>
#> <td class="gt_row gt_right">405</td></tr>
#>   </tbody>
#>   
#>   
#> </table>
#> </div>
plot(q.test)
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
#> [[4]]

#> 
#> [[5]]

#> 
#> [[6]]

#> 
#> [[7]]

#> 
#> [[8]]

#> 
#> [[9]]

#> 
#> [[10]]

#> 
print(q.test)
#> [[1]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable Type  m =  3  r =  1
#> Qp = 40.102, df = 26, p-value = 0.03812
#> 
#> 
#> [[2]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable Type  m =  3  r =  1
#> Qc = 26.507, df = 9, p-value = 0.001687
#> 
#> 
#> [[3]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable Type  m =  3  r =  2
#> Qp = 71.712, df = 26, p-value = 3.725e-06
#> 
#> 
#> [[4]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable Type  m =  3  r =  2
#> Qc = 64.671, df = 9, p-value = 1.672e-10
#> 
#> 
#> [[5]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable Type  m =  4  r =  1
#> Qp = 89.017, df = 80, p-value = 0.2297
#> 
#> 
#> [[6]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable Type  m =  4  r =  1
#> Qc = 28.831, df = 14, p-value = 0.01102
#> 
#> 
#> [[7]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable Type  m =  4  r =  2
#> Qp = 115.69, df = 80, p-value = 0.005592
#> 
#> 
#> [[8]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable Type  m =  4  r =  2
#> Qc = 44.19, df = 14, p-value = 5.516e-05
#> 
#> 
#> [[9]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable Type  m =  4  r =  3
#> Qp = 151.65, df = 80, p-value = 2.375e-06
#> 
#> 
#> [[10]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable Type  m =  4  r =  3
#> Qc = 81.256, df = 14, p-value = 1.654e-11
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   

# Case 3: With a sf object with isolated areas
data("provinces_spain")
sf::sf_use_s2(FALSE)
provinces_spain$Male2Female <- factor(provinces_spain$Male2Female > 100)
levels(provinces_spain$Male2Female) = 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 + Male2Female
q.test <- Q.test(formula = f1,
data = provinces_spain, m = 3, r = 1, control = list(seedinit = 1111))
summary(q.test)
#> <div id="vrzdqffzog" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
#>   <style>html {
#>   font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
#> }
#> 
#> #vrzdqffzog .gt_table {
#>   display: table;
#>   border-collapse: collapse;
#>   margin-left: auto;
#>   margin-right: auto;
#>   color: #333333;
#>   font-size: 16px;
#>   font-weight: normal;
#>   font-style: normal;
#>   background-color: #FFFFFF;
#>   width: auto;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #A8A8A8;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #A8A8A8;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_heading {
#>   background-color: #FFFFFF;
#>   text-align: center;
#>   border-bottom-color: #FFFFFF;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_title {
#>   color: #333333;
#>   font-size: 125%;
#>   font-weight: initial;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-color: #FFFFFF;
#>   border-bottom-width: 0;
#> }
#> 
#> #vrzdqffzog .gt_subtitle {
#>   color: #333333;
#>   font-size: 85%;
#>   font-weight: initial;
#>   padding-top: 0;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-color: #FFFFFF;
#>   border-top-width: 0;
#> }
#> 
#> #vrzdqffzog .gt_bottom_border {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_col_headings {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_col_heading {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   overflow-x: hidden;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   padding-top: 0;
#>   padding-bottom: 0;
#>   padding-left: 4px;
#>   padding-right: 4px;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer:first-child {
#>   padding-left: 0;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner_outer:last-child {
#>   padding-right: 0;
#> }
#> 
#> #vrzdqffzog .gt_column_spanner {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 5px;
#>   overflow-x: hidden;
#>   display: inline-block;
#>   width: 100%;
#> }
#> 
#> #vrzdqffzog .gt_group_heading {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #vrzdqffzog .gt_empty_group_heading {
#>   padding: 0.5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #vrzdqffzog .gt_from_md > :first-child {
#>   margin-top: 0;
#> }
#> 
#> #vrzdqffzog .gt_from_md > :last-child {
#>   margin-bottom: 0;
#> }
#> 
#> #vrzdqffzog .gt_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   margin: 10px;
#>   border-top-style: solid;
#>   border-top-width: 1px;
#>   border-top-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#>   overflow-x: hidden;
#> }
#> 
#> #vrzdqffzog .gt_stub {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_stub_row_group {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   vertical-align: top;
#> }
#> 
#> #vrzdqffzog .gt_row_group_first td {
#>   border-top-width: 2px;
#> }
#> 
#> #vrzdqffzog .gt_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_first_summary_row {
#>   border-top-style: solid;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_first_summary_row.thick {
#>   border-top-width: 2px;
#> }
#> 
#> #vrzdqffzog .gt_last_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_grand_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_first_grand_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-style: double;
#>   border-top-width: 6px;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_striped {
#>   background-color: rgba(128, 128, 128, 0.05);
#> }
#> 
#> #vrzdqffzog .gt_table_body {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_footnotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_footnote {
#>   margin: 0px;
#>   font-size: 90%;
#>   padding-left: 4px;
#>   padding-right: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_sourcenotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #vrzdqffzog .gt_sourcenote {
#>   font-size: 90%;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #vrzdqffzog .gt_left {
#>   text-align: left;
#> }
#> 
#> #vrzdqffzog .gt_center {
#>   text-align: center;
#> }
#> 
#> #vrzdqffzog .gt_right {
#>   text-align: right;
#>   font-variant-numeric: tabular-nums;
#> }
#> 
#> #vrzdqffzog .gt_font_normal {
#>   font-weight: normal;
#> }
#> 
#> #vrzdqffzog .gt_font_bold {
#>   font-weight: bold;
#> }
#> 
#> #vrzdqffzog .gt_font_italic {
#>   font-style: italic;
#> }
#> 
#> #vrzdqffzog .gt_super {
#>   font-size: 65%;
#> }
#> 
#> #vrzdqffzog .gt_footnote_marks {
#>   font-style: italic;
#>   font-weight: normal;
#>   font-size: 75%;
#>   vertical-align: 0.4em;
#> }
#> 
#> #vrzdqffzog .gt_asterisk {
#>   font-size: 100%;
#>   vertical-align: 0;
#> }
#> 
#> #vrzdqffzog .gt_slash_mark {
#>   font-size: 0.7em;
#>   line-height: 0.7em;
#>   vertical-align: 0.15em;
#> }
#> 
#> #vrzdqffzog .gt_fraction_numerator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: 0.45em;
#> }
#> 
#> #vrzdqffzog .gt_fraction_denominator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: -0.05em;
#> }
#> </style>
#>   <table class="gt_table">
#>   <thead class="gt_header">
#>     <tr>
#>       <th colspan="11" class="gt_heading gt_title gt_font_normal" style>Qualitative Dependence Test (Q)</th>
#>     </tr>
#>     <tr>
#>       <th colspan="11" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border" style>Distribution: asymptotic. Distance: Euclidean</th>
#>     </tr>
#>   </thead>
#>   <thead class="gt_col_headings">
#>     <tr>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">Q</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">df</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">p.value</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">k</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">N</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">m</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">r</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R/n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">5k^m</th>
#>     </tr>
#>   </thead>
#>   <tbody class="gt_table_body">
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">Older - standard-permutations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">29.40</td>
#> <td class="gt_row gt_right">26</td>
#> <td class="gt_row gt_right">0.29320</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">24</td>
#> <td class="gt_row gt_right">27</td>
#> <td class="gt_row gt_right">0.89</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">Older - equivalent-combinations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">8.95</td>
#> <td class="gt_row gt_right">9</td>
#> <td class="gt_row gt_right">0.44166</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">24</td>
#> <td class="gt_row gt_right">10</td>
#> <td class="gt_row gt_right">2.40</td>
#> <td class="gt_row gt_right">135</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">Male2Female - standard-permutations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">4.34</td>
#> <td class="gt_row gt_right">7</td>
#> <td class="gt_row gt_right">0.74025</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">24</td>
#> <td class="gt_row gt_right">8</td>
#> <td class="gt_row gt_right">3.00</td>
#> <td class="gt_row gt_right">40</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="11" class="gt_group_heading">Male2Female - equivalent-combinations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">0.69</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">0.87543</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">1</td>
#> <td class="gt_row gt_right">24</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">6.00</td>
#> <td class="gt_row gt_right">40</td></tr>
#>   </tbody>
#>   
#>   
#> </table>
#> </div>
print(q.test)
#> [[1]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable Older  m =  3  r =  1
#> Qp = 29.4, df = 26, p-value = 0.2932
#> 
#> 
#> [[2]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable Older  m =  3  r =  1
#> Qc = 8.9526, df = 9, p-value = 0.4417
#> 
#> 
#> [[3]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable Male2Female  m =  3  r =  1
#> Qp = 4.3369, df = 7, p-value = 0.7403
#> 
#> 
#> [[4]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable Male2Female  m =  3  r =  1
#> Qc = 0.69051, df = 3, p-value = 0.8754
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   
plot(q.test)
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
#> [[4]]

#> 
q.test.mc <- Q.test(formula = f1, data = provinces_spain, m = 4, r = 3, distr = "mc",
control = list(seedinit = 1111))
summary(q.test.mc)
#> <div id="friuvihjft" style="overflow-x:auto;overflow-y:auto;width:auto;height:auto;">
#>   <style>html {
#>   font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
#> }
#> 
#> #friuvihjft .gt_table {
#>   display: table;
#>   border-collapse: collapse;
#>   margin-left: auto;
#>   margin-right: auto;
#>   color: #333333;
#>   font-size: 16px;
#>   font-weight: normal;
#>   font-style: normal;
#>   background-color: #FFFFFF;
#>   width: auto;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #A8A8A8;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #A8A8A8;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_heading {
#>   background-color: #FFFFFF;
#>   text-align: center;
#>   border-bottom-color: #FFFFFF;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_title {
#>   color: #333333;
#>   font-size: 125%;
#>   font-weight: initial;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-color: #FFFFFF;
#>   border-bottom-width: 0;
#> }
#> 
#> #friuvihjft .gt_subtitle {
#>   color: #333333;
#>   font-size: 85%;
#>   font-weight: initial;
#>   padding-top: 0;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-color: #FFFFFF;
#>   border-top-width: 0;
#> }
#> 
#> #friuvihjft .gt_bottom_border {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_col_headings {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_col_heading {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 6px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   overflow-x: hidden;
#> }
#> 
#> #friuvihjft .gt_column_spanner_outer {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: normal;
#>   text-transform: inherit;
#>   padding-top: 0;
#>   padding-bottom: 0;
#>   padding-left: 4px;
#>   padding-right: 4px;
#> }
#> 
#> #friuvihjft .gt_column_spanner_outer:first-child {
#>   padding-left: 0;
#> }
#> 
#> #friuvihjft .gt_column_spanner_outer:last-child {
#>   padding-right: 0;
#> }
#> 
#> #friuvihjft .gt_column_spanner {
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: bottom;
#>   padding-top: 5px;
#>   padding-bottom: 5px;
#>   overflow-x: hidden;
#>   display: inline-block;
#>   width: 100%;
#> }
#> 
#> #friuvihjft .gt_group_heading {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #friuvihjft .gt_empty_group_heading {
#>   padding: 0.5px;
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   vertical-align: middle;
#> }
#> 
#> #friuvihjft .gt_from_md > :first-child {
#>   margin-top: 0;
#> }
#> 
#> #friuvihjft .gt_from_md > :last-child {
#>   margin-bottom: 0;
#> }
#> 
#> #friuvihjft .gt_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   margin: 10px;
#>   border-top-style: solid;
#>   border-top-width: 1px;
#>   border-top-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 1px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 1px;
#>   border-right-color: #D3D3D3;
#>   vertical-align: middle;
#>   overflow-x: hidden;
#> }
#> 
#> #friuvihjft .gt_stub {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #friuvihjft .gt_stub_row_group {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   font-size: 100%;
#>   font-weight: initial;
#>   text-transform: inherit;
#>   border-right-style: solid;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   vertical-align: top;
#> }
#> 
#> #friuvihjft .gt_row_group_first td {
#>   border-top-width: 2px;
#> }
#> 
#> #friuvihjft .gt_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #friuvihjft .gt_first_summary_row {
#>   border-top-style: solid;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_first_summary_row.thick {
#>   border-top-width: 2px;
#> }
#> 
#> #friuvihjft .gt_last_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_grand_summary_row {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   text-transform: inherit;
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #friuvihjft .gt_first_grand_summary_row {
#>   padding-top: 8px;
#>   padding-bottom: 8px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#>   border-top-style: double;
#>   border-top-width: 6px;
#>   border-top-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_striped {
#>   background-color: rgba(128, 128, 128, 0.05);
#> }
#> 
#> #friuvihjft .gt_table_body {
#>   border-top-style: solid;
#>   border-top-width: 2px;
#>   border-top-color: #D3D3D3;
#>   border-bottom-style: solid;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_footnotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_footnote {
#>   margin: 0px;
#>   font-size: 90%;
#>   padding-left: 4px;
#>   padding-right: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #friuvihjft .gt_sourcenotes {
#>   color: #333333;
#>   background-color: #FFFFFF;
#>   border-bottom-style: none;
#>   border-bottom-width: 2px;
#>   border-bottom-color: #D3D3D3;
#>   border-left-style: none;
#>   border-left-width: 2px;
#>   border-left-color: #D3D3D3;
#>   border-right-style: none;
#>   border-right-width: 2px;
#>   border-right-color: #D3D3D3;
#> }
#> 
#> #friuvihjft .gt_sourcenote {
#>   font-size: 90%;
#>   padding-top: 4px;
#>   padding-bottom: 4px;
#>   padding-left: 5px;
#>   padding-right: 5px;
#> }
#> 
#> #friuvihjft .gt_left {
#>   text-align: left;
#> }
#> 
#> #friuvihjft .gt_center {
#>   text-align: center;
#> }
#> 
#> #friuvihjft .gt_right {
#>   text-align: right;
#>   font-variant-numeric: tabular-nums;
#> }
#> 
#> #friuvihjft .gt_font_normal {
#>   font-weight: normal;
#> }
#> 
#> #friuvihjft .gt_font_bold {
#>   font-weight: bold;
#> }
#> 
#> #friuvihjft .gt_font_italic {
#>   font-style: italic;
#> }
#> 
#> #friuvihjft .gt_super {
#>   font-size: 65%;
#> }
#> 
#> #friuvihjft .gt_footnote_marks {
#>   font-style: italic;
#>   font-weight: normal;
#>   font-size: 75%;
#>   vertical-align: 0.4em;
#> }
#> 
#> #friuvihjft .gt_asterisk {
#>   font-size: 100%;
#>   vertical-align: 0;
#> }
#> 
#> #friuvihjft .gt_slash_mark {
#>   font-size: 0.7em;
#>   line-height: 0.7em;
#>   vertical-align: 0.15em;
#> }
#> 
#> #friuvihjft .gt_fraction_numerator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: 0.45em;
#> }
#> 
#> #friuvihjft .gt_fraction_denominator {
#>   font-size: 0.6em;
#>   line-height: 0.6em;
#>   vertical-align: -0.05em;
#> }
#> </style>
#>   <table class="gt_table">
#>   <thead class="gt_header">
#>     <tr>
#>       <th colspan="9" class="gt_heading gt_title gt_font_normal" style>Qualitative Dependence Test (Q)</th>
#>     </tr>
#>     <tr>
#>       <th colspan="9" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border" style>Distribution: mc. Distance: Euclidean</th>
#>     </tr>
#>   </thead>
#>   <thead class="gt_col_headings">
#>     <tr>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">Q</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">p.value</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">k</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">N</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">m</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">R/n</th>
#>       <th class="gt_col_heading gt_columns_bottom_border gt_right" rowspan="1" colspan="1">5k^m</th>
#>     </tr>
#>   </thead>
#>   <tbody class="gt_table_body">
#>     <tr class="gt_group_heading_row">
#>       <td colspan="9" class="gt_group_heading">Older - standard-permutations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">93.32</td>
#> <td class="gt_row gt_right">0.23500</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">81</td>
#> <td class="gt_row gt_right">0.62</td>
#> <td class="gt_row gt_right">405</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="9" class="gt_group_heading">Older - equivalent-combinations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">20.10</td>
#> <td class="gt_row gt_right">0.46800</td>
#> <td class="gt_row gt_right">3</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">15</td>
#> <td class="gt_row gt_right">3.33</td>
#> <td class="gt_row gt_right">405</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="9" class="gt_group_heading">Male2Female - standard-permutations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">18.06</td>
#> <td class="gt_row gt_right">0.46100</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">16</td>
#> <td class="gt_row gt_right">3.12</td>
#> <td class="gt_row gt_right">80</td></tr>
#>     <tr class="gt_group_heading_row">
#>       <td colspan="9" class="gt_group_heading">Male2Female - equivalent-combinations</td>
#>     </tr>
#>     <tr class="gt_row_group_first"><td class="gt_row gt_right">6.35</td>
#> <td class="gt_row gt_right">0.31300</td>
#> <td class="gt_row gt_right">2</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">4</td>
#> <td class="gt_row gt_right">50</td>
#> <td class="gt_row gt_right">5</td>
#> <td class="gt_row gt_right">10.00</td>
#> <td class="gt_row gt_right">80</td></tr>
#>   </tbody>
#>   
#>   
#> </table>
#> </div>
print(q.test.mc)
#> [[1]]
#> 
#> 	Qp (mc distrib.) for symbolization based on permutations
#> 
#> data:  Variable Older  m =  4  r =  3
#> Qp = 93.325, df = NA, p-value = 0.235
#> 
#> 
#> [[2]]
#> 
#> 	Qc (mc distrib.) for symbolization based on combinations
#> 
#> data:  Variable Older  m =  4  r =  3
#> Qc = 20.096, df = NA, p-value = 0.468
#> 
#> 
#> [[3]]
#> 
#> 	Qp (mc distrib.) for symbolization based on permutations
#> 
#> data:  Variable Male2Female  m =  4  r =  3
#> Qp = 18.062, df = NA, p-value = 0.461
#> 
#> 
#> [[4]]
#> 
#> 	Qc (mc distrib.) for symbolization based on combinations
#> 
#> data:  Variable Male2Female  m =  4  r =  3
#> Qc = 6.3535, df = NA, p-value = 0.313
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   
plot(q.test.mc)
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
#> [[4]]

#> 

# Case 4: Examples with multipolygons
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1; sf_use_s2() is FALSE
fname <- system.file("shape/nc.shp", package="sf")
nc <- sf::st_read(fname)
#> Reading layer `nc' from data source 
#>   `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27
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") )
#> 
#>  Threshold distance:  4.136024
#>  None m-surrounding excluded for exceeding
#>         the threshold distance 
#> 
#>  Threshold distance:  4.136024
#>  None m-surrounding excluded for exceeding
#>         the threshold distance 
print(lq1nc)
#> [[1]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable QSID79  m =  5  r =  2
#> Qp = 225.84, df = 1023, p-value = 1
#> 
#> 
#> [[2]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable QSID79  m =  5  r =  2
#> Qc = 61.371, df = 55, p-value = 0.2583
#> 
#> 
#> [[3]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable QBIR79  m =  5  r =  2
#> Qp = 221.81, df = 1023, p-value = 1
#> 
#> 
#> [[4]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable QBIR79  m =  5  r =  2
#> Qc = 59.272, df = 55, p-value = 0.3226
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   

lq2nc <- Q.test(formula = f1, data = nc, m = 5, r = 2,
control = list(dtmaxpc = 0.2) )
#> 
#>  Threshold distance:  1.65441
#>  Number of m-surroundings excluded for exceeding
#>         the threshold distance:  3 
#> 
#>  Index of spatial observations excluded:  19 3 28 
#> 
#>  Threshold distance:  1.65441
#>  Number of m-surroundings excluded for exceeding
#>         the threshold distance:  3 
#> 
#>  Index of spatial observations excluded:  19 3 28 
print(lq2nc)
#> [[1]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable QSID79  m =  5  r =  2
#> Qp = 210.14, df = 1023, p-value = 1
#> 
#> 
#> [[2]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable QSID79  m =  5  r =  2
#> Qc = 62.831, df = 55, p-value = 0.2186
#> 
#> 
#> [[3]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable QBIR79  m =  5  r =  2
#> Qp = 206.72, df = 1023, p-value = 1
#> 
#> 
#> [[4]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable QBIR79  m =  5  r =  2
#> Qc = 60.539, df = 55, p-value = 0.2828
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   

lq3nc <- Q.test(formula = f1, data = nc, m = 5, r = 2,
control = list(dtmaxknn = 5) )
print(lq3nc)
#> [[1]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable QSID79  m =  5  r =  2
#> Qp = 43.935, df = 1023, p-value = 1
#> 
#> 
#> [[2]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable QSID79  m =  5  r =  2
#> Qc = 18.923, df = 55, p-value = 1
#> 
#> 
#> [[3]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable QBIR79  m =  5  r =  2
#> Qp = 44.361, df = 1023, p-value = 1
#> 
#> 
#> [[4]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable QBIR79  m =  5  r =  2
#> Qc = 20.16, df = 55, p-value = 1
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   

# 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(st_geometry(nc)))
mcoor <- 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))
#> 
#>  Threshold distance:  4.136024
#>  None m-surrounding excluded for exceeding
#>         the threshold distance 
#> 
#>  Threshold distance:  4.136024
#>  None m-surrounding excluded for exceeding
#>         the threshold distance 
print(q.test)
#> [[1]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable V1  m =  5  r =  2
#> Qp = 221.87, df = 1023, p-value = 1
#> 
#> 
#> [[2]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable V1  m =  5  r =  2
#> Qc = 55.411, df = 55, p-value = 0.4591
#> 
#> 
#> [[3]]
#> 
#> 	Qp (asymptotic distrib.) for standard symbolization based on
#> 	permutations
#> 
#> data:  Variable V2  m =  5  r =  2
#> Qp = 220.68, df = 1023, p-value = 1
#> 
#> 
#> [[4]]
#> 
#> 	Qc (asymptotic distrib.) for equivalent symbolization based on
#> 	combinations
#> 
#> data:  Variable V2  m =  5  r =  2
#> Qc = 38.975, df = 55, p-value = 0.9498
#> 
#> 
#> attr(,"class")
#> [1] "spqtest" "list"   
plot(q.test)
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
#> [[4]]

#> 

# }