forked from r-spatialecology/shar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
107 lines (71 loc) · 7.41 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
fig.path = "man/figures/README-"
)
```
<!-- badges: start -->
| Continuous Integration | Development | CRAN | License |
|------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| [](https://github.com/r-spatialecology/shar/actions) | [](https://www.repostatus.org/#active) | [](https://cran.r-project.org/package=shar) | [](https://www.gnu.org/licenses/gpl-3.0) |
| [](https://codecov.io/gh/r-spatialecology/shar?branch=main) | [](https://www.tidyverse.org/lifecycle/#stable) | [](http://cran.rstudio.com/web/packages/shar/index.html) | |
<!-- badges: end -->
<img src="man/figures/logo.png" align="right" width="150" />
# shar
**S**pecies-**H**abitat **A**ssociations in **R** is a `R` package to analyze species-habitat associations. Therefore, information about the location of the species is needed (as a point pattern) and about the environmental conditions (as a raster map). In order to analyse the data for significant habitat associations either the location data or the environmental data is randomized n-times. Then, counts within the habitats are compared between the randomized data and the observed data. Positive or negative associations are present if the observed counts is higher or lower than the randomized counts (using quantile thresholds). Methods are mainly described in Plotkin et al. (2000), Harms et al. (2001) and Wiegand & Moloney (2014). **shar** is mainly based on the `spatstat` (Baddeley et al. 2015) and `raster` (Hijmans 2017) package.
## Installation
You can install the released version of **shar** from [CRAN](https://cran.r-project.org/web/packages/shar/index.html) with:
```{r install-CRAN, eval = FALSE}
install.packages("shar")
```
And the development version from [GitHub](https://github.com/r-spatialecology/shar) with:
```{r install-github, eval = FALSE}
# install.packages("devtools")
devtools::install_github("r-spatialecology/shar")
```
## How to use shar
```{r import-libs, message = FALSE}
library(shar)
library(raster)
```
**shar** comes with build-in example data sets. `species_a` and `species_b` are exemplary location of species, e.g. trees, as `ppp`-objects from the `spatstat` package. `landscape` contains examplary continuous environmental data. However, all methods depend on discrete data. Therefore we need to classify the data first.
```{r environmental-data}
landscape_classified <- classify_habitats(raster = landscape, classes = 5)
```
There are two possibilities to randomize the environmental data, both described in Harms et al. (2001). The first shifts the habitat map in all 4 cardinal directions around a torus. The second one assigns the habitat values to an empty map using a random walk algorithm. Both functions return a list with randomized rasters and the observed one. For more information on the methods, please click [here](https://r-spatialecology.github.io/shar/articles/background.html).
```{r habitat_random, eval = FALSE}
torus_trans <- translate_raster(raster = landscape_classified, verbose = FALSE)
random_walk <- randomize_raster(raster = landscape_classified, n_random = 39, verbose = FALSE)
```
```{r plot_habitat-random, fig.width = 5.5, fig.height = 4, fig.align = "center"}
col = c("#440154FF", "#3B528BFF", "#21908CFF", "#5DC863FF", "#FDE725FF")
plot_randomized_raster(torus_trans, n = 3, col = col)
```
To randomize the point pattern, either use the Gamma test described by Plotkin et al. (2000) or pattern reconstruction (Tscheschel & Stoyan 2006).
```{r pattern-random, eval = FALSE}
gamma_test <- fit_point_process(pattern = species_a, process = "cluster", n_random = 39, verbose = FALSE)
reconstruction <- reconstruct_pattern_cluster(pattern = species_b, n_random = 39, verbose = FALSE) # takes some time
```
Of course, there are several utility functions. For example, you can plot a randomized pattern or calculate the differences between the observed pattern and the randomized patterns (using summary functions).
```{r plot-random_pattern, fig.width = 5.5, fig.height = 4, fig.align = "center"}
plot_randomized_pattern(reconstruction, verbose = FALSE, ask = FALSE)
```
```{r calculate-energy}
calculate_energy(reconstruction, verbose = FALSE)
```
The data was created that `species_a` has a negative association to habitat 4 and `species_b` has a positive association to habitat 5. At one point a positive association to one habitat leads consequently to a negative association to another habitat (and vice versa). All this can be seen in the results.
```{r results}
results_habitat_association(pattern = species_a, raster = torus_trans)
results_habitat_association(pattern = reconstruction, raster = landscape_classified)
```
## References
Baddeley, A., Rubak, E., Turner, R. (2015). Spatial Point Patterns: Methodology and Applications with R. London:Chapman and Hall/CRC Press, 2015. http://www.crcpress.com/Spatial-Point-Patterns-Methodology-and-Applications-with-R/Baddeley-Rubak-Turner/9781482210200/
Harms, K. E., Condit, R., Hubbell, S. P., & Foster, R. B. (2001). Habitat associations of trees and shrubs in a 50-ha neotropical forest plot. Journal of Ecology, 89(6), 947-959.
Hijmans, R. J. (2017). raster: Geographic Data Analysis and Modeling. R package version 2.6-7. https://CRAN.R-project.org/package=raster
Plotkin, J. B., Potts, M. D., Leslie, N., Manokaran, N., LaFrankie, J. V., & Ashton, P. S. (2000). Species-area curves, spatial aggregation, and habitat specialization in tropical forests. Journal of Theoretical Biology, 207(1), 81-99.
Tscheschel, A., & Stoyan, D. (2006). Statistical reconstruction of random point patterns. Computational Statistics and Data Analysis, 51(2), 859-871.
Wiegand, T., & Moloney, K. A. (2014). Handbook of spatial point-pattern analysis in ecology. Boca Raton: Chapman and Hall/CRC Press.