-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
105 lines (74 loc) · 4.85 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# sabre <img src="man/figures/logo.png" align="right" width="150" />
[![CRAN status](http://www.r-pkg.org/badges/version/sabre)](https://cran.r-project.org/package=sabre)
[![R-CMD-check](https://github.com/Nowosad/sabre/workflows/R-CMD-check/badge.svg)](https://github.com/Nowosad/sabre/actions)
[![codecov](https://app.codecov.io/gh/Nowosad/sabre/branch/master/graph/badge.svg)](https://app.codecov.io/gh/Nowosad/sabre)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/sabre)](https://cran.r-project.org/package=sabre)
The **sabre** (**S**patial **A**ssociation **B**etween **RE**gionalizations) is an R package for calculating a degree of spatial association between regionalizations or categorical maps.
This package offers support for `sf`, `RasterLayer`, `SpatRaster`, and `stars` spatial objects, and the following methods:
* the V-measure method (Nowosad and Stepinski, 2018)
* the MapCurve method (Hargrove et al., 2006)
## Installation
You can install the released version of `sabre` from [CRAN](https://cran.r-project.org/package=sabre) with:
``` r
install.packages("sabre")
```
You can install the development version from [GitHub](https://github.com/nowosad/sabre) with:
``` r
# install.packages("devtools")
devtools::install_github("Nowosad/sabre")
```
## Example
We use two simple regionalization, `regions1` and `regions2` to show the basic concept of calculating a degree of spatial association.
```{r, message=FALSE, warning=FALSE}
library(sabre)
library(sf)
data("regions1")
data("regions2")
```
The first map, `regions1` consists of four regions of the same shape and size, while the second one, `regions2` has three irregular regions.
```{r, echo=FALSE, fig.height=5, out.width="50%"}
plot(regions1, main = "regions1")
plot(regions2, main = "regions2")
```
The `vmeasure_calc()` function allows for calculation of a degree of spatial association between regionalizations or categorical maps using the information-theoretical V-measure.
It requires, at least, four arguments:
* `x` - an `sf` object containing the first regionalization
* `x_name` - a name of the column with regions names of the first regionalization
* `y` - an `sf` object containing the second regionalization
* `y_name` - a name of the column with regions names of the second regionalization
```{r}
regions_vm = vmeasure_calc(x = regions1, y = regions2, x_name = z, y_name = z)
```
The result is a list with three metrics of spatial association - `V-measure`, `Homogeneity`, `Completeness` - and two `sf` objects with preprocessed input maps - `$map1` and `$map2`.
```{r}
regions_vm
```
Both spatial outputs have two columns.
The first one contains regions' names/values and the second one (`rih`) describes regions' inhomogeneities.
```{r, eval=FALSE}
plot(regions_vm$map1["rih"], main = "Map1: rih")
plot(regions_vm$map2["rih"], main = "Map2: rih")
```
```{r, warning=FALSE, fig.height=2, fig.height=5, out.width="50%", echo=FALSE}
plot(regions_vm$map1["rih"], main = "Map1: rih"); plot(regions_vm$map2["rih"], main = "Map2: rih")
```
More examples can be found in [the package vignette](https://jakubnowosad.com/sabre/articles/sabre.html) and in [the sabre: or how to compare two maps? blog post](https://jakubnowosad.com/posts/2018-09-10-sabre-bp/).
<!-- Additionally, examples presented in the [Spatial association between regionalizations using the information-theoretical V-measure](https://doi.org/10.1080/13658816.2018.1511794) article can be reproduced using data available at http://sil.uc.edu/index.php?id=data-1#vmeasure. -->
## Logo
Hex logo was created with [hexmake](https://connect.thinkr.fr/hexmake/) using icons made by <a href="https://www.flaticon.com/authors/smashicons" title="Smashicons">Smashicons</a> and <a href="https://www.flaticon.com/authors/creaticca-creative-agency" title="Creaticca Creative Agency">Creaticca Creative Agency</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>.
## References
- Nowosad, Jakub, and Tomasz F. Stepinski. "Spatial association between regionalizations using the information-theoretical V-measure." International Journal of Geographical Information Science (2018). https://doi.org/10.1080/13658816.2018.1511794
- Rosenberg, Andrew, and Julia Hirschberg. "V-measure: A conditional entropy-based external cluster evaluation measure." Proceedings of the 2007 joint conference on empirical methods in natural language processing and computational natural language learning (EMNLP-CoNLL). 2007.
- Hargrove, William W., Forrest M. Hoffman, and Paul F. Hessburg. "Mapcurves: a quantitative method for comparing categorical maps." Journal of Geographical Systems 8.2 (2006): 187.