-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
116 lines (86 loc) · 6.04 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
104
105
106
107
108
109
110
111
112
113
114
115
116
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
error = FALSE,
warning = FALSE,
message = FALSE,
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# spatialsampler: An Implementation of Centric Systematic Area Sampling (CSAS) and Simple Spatial Sampling Method (S3M) in R <img src="man/figures/spatialsampler.png" width="200" align="right" />
<!-- badges: start -->
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/spatialsampler)](https://cran.r-project.org/package=spatialsampler)
[![CRAN](http://www.r-pkg.org/badges/last-release/spatialsamplers)](https://cran.r-project.org/package=spatialsampler)
[![CRAN status](http://cranlogs.r-pkg.org/badges/grand-total/spatialsampler)](https://cran.r-project.org/package=spatialsampler)
[![CRAN status](http://cranlogs.r-pkg.org/badges/spatialsampler)](https://cran.r-project.org/package=spatialsampler)
[![Travis-CI Build Status](https://travis-ci.org/SpatialWorks/spatialsampler.svg?branch=master)](https://travis-ci.org/SpatialWorks/spatialsampler)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/SpatialWorks/spatialsampler?branch=master&svg=true)](https://ci.appveyor.com/project/SpatialWorks/spatialsampler)
[![codecov](https://codecov.io/gh/SpatialWorks/spatialsampler/branch/master/graph/badge.svg)](https://codecov.io/gh/SpatialWorks/spatialsampler)
[![CodeFactor](https://www.codefactor.io/repository/github/spatialworks/spatialsampler/badge)](https://www.codefactor.io/repository/github/spatialworks/spatialsampler)
<!-- badges: end -->
The Centric Systematic Area Sampling (CSAS) and the Simple Spatial Survey Method (S3M) are spatial sampling methods adapted and used in health and nutrition surveys by Brixton Health and Valid International. CSAS and S3M are used in surveys designed to be spatially representative i.e., the sample distributed evenly across the survey area, using a spatial sample design that selected communities located closest to the centroids of a square (for CSAS) or hexagonal (for S3M) grid laid over the survey area.
The `spatialsampler` package provides sets of functions for implementing the Centric Systematic Area Sampling (CSAS) and Simple Spatial Sampling Method (S3M) using R.
## Installation
You can install `spatialsampler` from [GitHub](https://github.com/spatialworks/spatialsampler) with:
```{r install, echo = TRUE, eval = TRUE}
## Install
if(!require(remotes)) install.packages("remotes")
remotes::install_github("spatialworks/spatialsampler")
## Load
library(spatialsampler)
```
## Usage
The current functions in `spatialsampler` can be grouped into two (2) classes: *calculator* functions and *sampling* functions.
The *calculator* functions support the estimation of spatial sampling parameters needed for CSAS and S3M. These include the calculation of areas of grids, calculation of `d` value in kilometres that the grid area represents, calculation of height and length of rectangular grid for S3M and calculation of number of grids given the sampling area and d value or area size of grids.
The *sampling* functions support the implementation of the CSAS or S3M sampling.
### Calculator functions
1. `calculate_area()`
Calculates the area size of the resulting hexagon in a hexagonal grid and the area size of the resulting triangle in a triangular grid for a specified value of `d` (in kms) used in the simple spatial sampling method (S3M).
Given a $d$ of 10 kms, area can be calculated as follows:
```{r, echo = TRUE, eval = TRUE}
calculate_area(d = 10, digits = 2)
```
The result is a data frame of 1 row and 2 columns. The first column gives the area of the triangular grid (in kms) and the second column gives the area of the hexagonal grid (in kms).
### Sampling functions
1. Create a hexagonal sampling grid based on a d of 15 kms
```{r, echo = TRUE, eval = TRUE}
## Subset Sudan map to Sennar state map
sennar <- subset(sudan01, STATE == "Sennar")
## Create sampling grid
samp.points <- create_sp_grid(x = sennar,
d = 15,
buffer = 10,
country = "Sudan")
```
`create_sp_grid()` creates
```{r, echo = TRUE, eval = TRUE}
hex.samp <- sp::HexPoints2SpatialPolygons(samp.points)
villages.sp <- get_nearest_point(data = sennar_villages,
data.x = "x",
data.y = "y",
query = samp.points,
duplicate = FALSE)
```
```{r grid1, echo = FALSE, eval = TRUE, fig.cap = "Sampling map of Sennar at d = 15 kms", fig.align = "center", fig.pos = "h", fig.width = 10, fig.height = 10, fig.retina = 1}
raster::plot(sennar, lwd = 1.5)
points(sennar_villages[ , c("x", "y")], pch = 20, cex = 0.7, col = "darkgreen")
raster::plot(hex.samp, lwd = 1, border = "gray70", add = TRUE)
raster::plot(samp.points, pch = 1, cex = 1.75, lwd = 2, col = "blue", bg = NA, add = TRUE)
raster::text(samp.points, labels = 1:nrow(samp.points@coords), cex = 0.6)
points(villages.sp[ , c("x", "y")], pch = 4, cex = 0.7, col = "red")
text(villages.sp[ , c("x", "y")], labels = villages.sp$spid, cex = 0.7)
```
```{r grid2, echo = FALSE, eval = TRUE, fig.cap = "Sampling map of Sennar at d = 15 kms with buffering", fig.align = "center", fig.pos = "h", fig.width = 10, fig.height = 10, fig.retina = 1}
sennar_grid <- spatialsampler::create_sp_grid(x = sennar, d = 15, country = "Sudan")
raster::plot(sennar, lwd = 1.5)
raster::plot(sennar_grid, pch = 4, lwd = 2, col = "red", add = TRUE)
points(sennar_villages[ , c("x", "y")], pch = 20, cex = 0.5, col = "blue")
raster::plot(sp::HexPoints2SpatialPolygons(sennar_grid), border = "gray70", lwd = 1, add = TRUE)
```