Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inbo/grtsdb
Spatially balanced sampling based on the General Randomized Tessellation Stratified (GRTS) using R and SQLite
https://github.com/inbo/grtsdb
grts r r-package r-stats sampling sampling-methods sqlite
Last synced: 5 days ago
JSON representation
Spatially balanced sampling based on the General Randomized Tessellation Stratified (GRTS) using R and SQLite
- Host: GitHub
- URL: https://github.com/inbo/grtsdb
- Owner: inbo
- License: gpl-3.0
- Created: 2019-05-10T07:16:17.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-10T10:28:34.000Z (almost 3 years ago)
- Last Synced: 2024-05-01T12:39:51.564Z (7 months ago)
- Topics: grts, r, r-package, r-stats, sampling, sampling-methods, sqlite
- Language: R
- Homepage: https://inbo.github.io/grtsdb/
- Size: 440 KB
- Stars: 1
- Watchers: 8
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Citation: CITATION.cff
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# grtsdb
[![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: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)
![GitHub](https://img.shields.io/github/license/inbo/grtsdb)
[![R build status](https://github.com/inbo/grtsdb/workflows/R-CMD-check/badge.svg)](https://github.com/inbo/grtsdb/actions)
[![Codecov test coverage](https://codecov.io/gh/inbo/grtsdb/branch/master/graph/badge.svg)](https://app.codecov.io/gh/inbo/grtsdb?branch=master)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/inbo/grtsdb.svg)
![GitHub repo size](https://img.shields.io/github/repo-size/inbo/grtsdb.svg)The goal of `grtsdb` is to create a spatially balanced sample based on the 'Generalised Random Tesselation Stratified' strategy.
We store the base schema in an SQLite database to make the sampling reproducible.
Sampling the same database with the same parameters yields a stable sample.## Installation
To install the latest stable version use
``` r
# activate the INBO r-universe
options(
repos = c(
INBO = 'https://inbo.r-universe.dev', CRAN = 'https://cloud.r-project.org'
)
)
install.packages("grtsdb")
```You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("inbo/grtsdb")
```## Example
This is a basic example.
Connect to a database.
```{r}
tmp_copy <- tempfile(pattern = "grts", fileext = ".sqlite")
if (system.file("grts.sqlite", package = "grtsdb") != "") {
file.copy(system.file("grts.sqlite", package = "grtsdb"), tmp_copy)
}
library(grtsdb)
db <- connect_db(tmp_copy)
```To extract a sample, you'll need to specify the bounding box in projected coordinates and the size of the grid cells.
```{r example}
bbox <- rbind(
c(0, 32),
c(0, 32)
)
extract_sample(grtsdb = db, samplesize = 10, bbox = bbox, cellsize = 1)
```Repeating the sample yields the same results.
```{r}
extract_sample(grtsdb = db, samplesize = 10, bbox = bbox, cellsize = 1)
``````{r echo = FALSE}
drop_legacy_sites(grtsdb = db, level = 5)
```You can add legacy sites to the sampling scheme.
```{r}
legacy <- rbind(
c(4, 4),
c(17, 6)
)
add_legacy_sites(legacy, bbox = bbox, cellsize = 1, grtsdb = db)
extract_legacy_sample(grtsdb = db, samplesize = 10, bbox = bbox, cellsize = 1)
```You can compact the database for storage.
```{r}
compact_db(db)
```Disconnect the database when done.
```{r}
dbDisconnect(db)
``````{r eval = system.file("grts.sqlite", package = "grtsdb") == "", echo = FALSE}
dir.create("inst", showWarnings = FALSE)
file.copy(tmp_copy, file.path("inst", "grts.sqlite"))
```