<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/sabre-or-how-to-compare-two-maps/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://nowosad.github.io/post/sabre-bp/"> Rstats on Jakub Nowosad's website</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Creating or determination of regions is a useful way to describe the world.<br>
Regionalization does not only allow for a quicker understanding of spatial patterns but also can influence how regions are managed.<br>
Regions are created in various disciplines.<br>
We can delineate regions based on a single property (e.g. landform regions or climate regions) or several factors (e.g. ecoregions).<br>
There are also political regions divided by borders that are established through political or social agreements.<br>
Regions are powerful also because they can be easily visualized.</p>
<p>On the other hand, it is difficult to compare different regionalizations.<br>
For example, you have two regionalizations based on the same property but from two different times and you want to know how similar they are to each other and where the largest change had occurred.<br>
Another example is when you have two maps of the same property created by two different entities and you want to know where they are in agreement and where they are very different.<br>
Comparing different regionalizations also apply when we have two maps of different properties and we want to know is there a spatial relationship between the first regionalization and the second one.</p>
<div>
<img src="https://i1.wp.com/nowosad.github.io/post/2018-09-10-sabre-bp_files/03_sabre.png?w=456&ssl=1" data-recalc-dims="1">
<p>European countries map (left). Biogeographical regions of Europe (right)</p>
</div>
<p>The figure above is the simplest way of comparison – a visual approach by plotting two maps side by side.<br>
Now you could take a look at the map on the left, decide on some area of interest and next try to locate the same area on the map on the right side.<br>
Alternatively, it is possible to use lines to indicate the first regionalization, and color to express the second regionalization:</p>
<div>
<img src="https://i1.wp.com/nowosad.github.io/post/2018-09-10-sabre-bp_files/04_sabre.png?w=456&ssl=1" data-recalc-dims="1">
<p>Borders of European countries superimposed on the biogeographical regions of Europe</p>
</div>
<p>This way it is easy to see that the Netherlands lies in only one biogeographic region “Atlantic”, while some countries are in two or more biogeographic regions.<br>
There are also several ways to compare regionalization maps interactively, for example using <a rel="nofollow" href="https://www.rdocumentation.org/packages/tmap/versions/2.1-1/topics/tmap_arrange?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank"><code>tmap::tmap_arrange()</code> in the view mode</a> or the <a rel="nofollow" href="https://www.rdocumentation.org/packages/mapview/versions/2.5.0/topics/slideView?tap_a=5644-dce66f&tap_s=10907-287229" target="_blank"><code>mapview::slideView()</code></a> function.</p>
<p>There is still one issue though – how to compare two regionalizations quantitatively?<br>
In other words – how to calculate a similarity between two regionalizations or categorical maps?<br>
For this purpose, we developed a new R package called <strong>sabre</strong>, which stands for <strong>S</strong>patial <strong>A</strong>ssociation <strong>B</strong>etween <strong>RE</strong>egionalizations.<br>
You can download it from CRAN:</p>
<pre><code>install.packages(&quot;sabre&quot;)
</code></pre>
<p>In this blogpost, we will use only two R packages:</p>
<pre><code># attach packages
library(sf)
library(sabre)
</code></pre>
<p>Additionally, <strong>ggplot2</strong> was used to create the maps and <strong>gganimate</strong> to create the animations.</p>
<h2>Data</h2>
<p>Let’s try this package by using the two datasets mentioned above – the first one consists of counties borders and the second one represents biogeographical regions of Europe.<br>
They could be downloaded through R with:</p>
<pre><code># data download
url = &quot;http://sil.uc.edu/cms/data/uploads/software_data/vmeasure/regions.zip&quot;
download.file(url, destfile = &quot;regions.zip&quot;)
unzip(&quot;regions.zip&quot;, exdir = &quot;data&quot;)
</code></pre>
<p>Importantly, <strong>sabre</strong> requires that two input datasets have the same coordinate reference system (CRS).<br>
If your datasets have different CRS’s, you can transform one of the datasets to have the same CRS as the second one.<br>
To learn more read the section about<br>
<a rel="nofollow" href="https://geocompr.robinlovelace.net/reproj-geo-data.html#reproj-vec-geom" target="_blank">reprojecting vector geometries</a> from the <a rel="nofollow" href="https://geocompr.robinlovelace.net/" target="_blank">Geocomputation with R</a> book.</p>
<p>Next, we just need to read the data:</p>
<pre><code># read data
europe_borders = st_read(&quot;data/europe_borders.gpkg&quot;, quiet = TRUE)
biogeo_regions = st_read(&quot;data/biogeo_regions.gpkg&quot;, quiet = TRUE)
</code></pre>
<p>Note: the <strong>sabre</strong> package expects data with valid geometries only.<br>
You can fix invalid geometries with <code>lwgeom::st_make_valid()</code>.</p>
<h2>V-measure</h2>
<p>The main function in <strong>sabre</strong> is <code>vmeasure_calc()</code>.<br>
It calculates a degree of spatial association between two regionalizations using an information-theoretical measure called the V-measure.<br>
We adapted this measure from computer science, where it is used to compare (non-spatial) clusterings (<a rel="nofollow" href="http://www.aclweb.org/anthology/D07-1043" target="_blank">Rosenberg and Hirschberg, 2007</a>).</p>
<p>V-measure is built upon two intermediate metrics – homogeneity and completeness.<br>
Homogeneity is a measure of how well regions from the first map fit inside of regions from the second map.<br>
Completeness measures how well regions from the second map fit inside of regions from the first map.<br>
The final value of v-measure is calculated as the weighted harmonic mean of homogeneity and completeness.<br>
All of these metrics have values between 0 and 1, where larger values indicate better spatial agreement.</p>
<h2>Comparision between two maps</h2>
<p>The <code>vmeasure_calc()</code> function requires four arguments:</p>
<ul>
<li><code>x</code> – a name of spatial object (map 1)</li>
<li><code>x_name</code> – a name of the column with regions/clusters names in map 1</li>
<li><code>y</code> – a name of spatial object (map 2)</li>
<li><code>y_name</code> – a name of the column with regions/clusters names in map 2</li>
</ul>
<p>Let’s apply v-measure to compare our two maps:</p>
<pre><code>sabre_output = vmeasure_calc(europe_borders, name, biogeo_regions, code)
</code></pre>
<p>The output gives five elements – values of v-measure, homogeneity, and completeness and two maps:</p>
<pre><code>sabre_output
</code></pre>
<pre><code>## The SABRE results:
## 
##  V-measure: 0.47 
##  Homogeneity: 0.38 
##  Completeness: 0.61 
## 
##  The spatial objects could be retrived with:
##  $map1 - the first map
##  $map2 - the second map
</code></pre>
<p>V-measure, homogeneity, and completeness are global measures of association between the two regionalizations.<br>
Additional two maps indicate local associations by presenting regions’ inhomogeneities (<strong>rih</strong>).<br>
The first map shows how inhomogenous are countries with respect to biogeographical regions.<br>
For example, inhomogeneity of the Netherlands is zero as the country lies in only one biogeographical region and inhomogeneity of France is 0.63 as the country is divided by four different biogeographical regions.<br>
This measure also takes the area of biogeographical regions that cover each country into consideration.<br>
Both Poland and Belarus have two biogeographical regions, however in Poland, one region dominates the country area (rih = 0.08) and Belarus is almost equally divided by two regions (rih = 0.38).</p>
<div>
<img src="https://i0.wp.com/nowosad.github.io/post/2018-09-10-sabre-bp_files/map21_anim.gif?w=456&ssl=1" data-recalc-dims="1">
<p>A map of inhomogeneity of countries in terms of biogeographical regions</p>
</div>
<p>The second map represents how inhomogenous biogeographical regions are with respect to countries:</p>
<div>
<img src="https://i2.wp.com/nowosad.github.io/post/2018-09-10-sabre-bp_files/map22_anim.gif?w=456&ssl=1" data-recalc-dims="1">
<p>A map of inhomogeneity of biogeographical regions in terms of countries</p>
</div>
<h2>Additional applications</h2>
<p>This blog post focuses on providing the basic understanding of the spatial association between regionalizations.<br>
However, this method has a broader spectrum of possible applications, which we divide into three basic groups: comparative, associative, and derivative.<br>
In this blog post, we show an example of the comparative context.<br>
The associative context is used when you need to asses a degree of correspondence between a map of regions and maps of possible influencing factors.<br>
The role of derivative context is to help to select a number of spatial clusters.<br>
To learn more about all of these contexts take a look at our paper <a rel="nofollow" href="https://doi.org/10.1080/13658816.2018.1511794" target="_blank">“Spatial association between regionalizations using the information-theoretical V-measure”</a>.<br>
A freely available preprint is at <a rel="nofollow" href="https://eartharxiv.org/rcjh7/" target="_blank">https://eartharxiv.org/rcjh7/</a>.</p>
<h2>Quick summary</h2>
<p><strong>S</strong>patial <strong>A</strong>ssociation <strong>B</strong>etween <strong>RE</strong>egionalizations, <strong>sabre</strong>, is a spatial method adapted from computer science.<br>
It allows for three main types of analysis – comparative (comparison of regions), associative (relation between a regionalization and factor maps), and derivative (obtaining an optimal number of clusters).<br>
We implemented this method as an open-source software – an R package called <strong>sabre</strong>.<br>
This package allows for comparisons of maps in a form of vector objects.<br>
Let us know if you also want a support for raster map using <a rel="nofollow" href="https://github.com/Nowosad/sabre/issues/3" target="_blank">the GitHub issue</a>.<br>
To learn more you can visit <a rel="nofollow" href="https://nowosad.github.io/sabre/index.html" target="_blank">the package website</a>,<br>
read the <a rel="nofollow" href="http://www.aclweb.org/anthology/D07-1043" target="_blank">original V-measure</a> paper or our article <a rel="nofollow" href="https://eartharxiv.org/rcjh7/" target="_blank">“Spatial association between regionalizations using the information-theoretical V-measure”</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://nowosad.github.io/post/sabre-bp/"> Rstats on Jakub Nowosad's website</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/-LxTYFEnLmI" height="1"></a></div>