Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/inbo/territoria


https://github.com/inbo/territoria

bird breeding cluster home-range r territory

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = file.path("man", "figures", "README-"),
out.width = "100%"
)
```

# territoria

[![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: stable](https://lifecycle.r-lib.org/articles/figures/lifecycle-stable.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![License](https://img.shields.io/badge/license-GPL--3-blue.svg?style=flat)](https://www.gnu.org/licenses/gpl-3.0.html)
![GitHub](https://img.shields.io/github/license/inbo/territoria)
[![R build status](https://github.com/inbo/territoria/workflows/check%20package%20on%20main/badge.svg)](https://github.com/inbo/territoria/actions)
[![Codecov test coverage](https://codecov.io/gh/inbo/territoria/branch/main/graph/badge.svg)](https://app.codecov.io/gh/inbo/territoria?branch=main)
![r-universe name](https://inbo.r-universe.dev/badges/:name?color=c04384)
![r-universe package](https://inbo.r-universe.dev/badges/territoria)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/inbo/territoria.svg)
![GitHub repo size](https://img.shields.io/github/repo-size/inbo/territoria.svg)

The goal of `territoria` is to cluster observations from different breeding bird surveys into territoria.

## Installation

You can install the development version from [GitHub](https://github.com/) with:

``` r
# install.packages("remotes")
remotes::install_github("inbo/territoria")
```

## Example

We start by simulating some observations.
We need for every observation their `x` and `y` coordinates in a projected coordinate system.
`survey` is an integer id for every survey.
A survey is a unique combination of an area and date.
`status` is an integer indication the breeding status.
A higher value assume more certainty about breeding.
Set this to a constant value if you don't distinct between different certainties.
In this example we use three classes: `1`, `2` and `3`.

```{r sim-data}
library(territoria)
set.seed(20210806)
obs <- simulate_observations()
names(obs)
summary(obs$centroids)
summary(obs$observations)
obs <- obs$observations[obs$observations$observed, ]
```

Once we have a data.frame with the observations, we connect to a SQLite database and import the observations.
This assigns every observation to its own cluster.

```{r import-data}
conn <- connect_db()
import_observations(observations = obs, conn = conn, max_dist = 336)
result <- get_cluster(conn = conn)
nrow(result$observations) == nrow(result$cluster)
```

Next, we need to calculate the distance matrix.
This is not the full distance matrix.
We omit all irrelevant distances, e.g. between observations from the same survey or with a distance larger than twice the maximum cluster distance.

```{r distance}
distance_matrix(conn = conn, max_dist = 366)
```

Now we can start the clustering.
The clustering takes into account all observations with a `status` greater than or equal to the set status.

```{r cluster-3}
cluster_observation(conn = conn, status = 3, max_dist = 336)
result3 <- get_cluster(conn = conn)
nrow(result3$observations) > nrow(result3$cluster)
```

Repeat the clustering for every status level.
Note that skipping levels implies that we combine them with the lower level.

```{r cluster-1}
cluster_observation(conn = conn, status = 1, max_dist = 336)
result1 <- get_cluster(conn = conn)
nrow(result1$observations) > nrow(result1$cluster)
nrow(result3$cluster) > nrow(result1$cluster)
summary(result1$observations)
summary(result1$cluster)
```