-
Notifications
You must be signed in to change notification settings - Fork 0
/
Random.Rmd
119 lines (87 loc) · 4.17 KB
/
Random.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
117
118
119
---
title: "Random Spatial Communities"
output: rmarkdown::html_vignette
bibliography: ../../inst/REFERENCES.bib
vignette: >
%\VignetteIndexEntry{Random Spatial Communities}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r global_options, include=FALSE}
# Installation of packages if necessary
InstallPackages <- function(Packages) {
InstallPackage <- function(Package) {
if (!Package %in% installed.packages()[, 1]) {
install.packages(Package, repos="https://cran.rstudio.com/")
}
}
invisible(sapply(Packages, InstallPackage))
}
InstallPackages(c("magrittr", "spatstat", "dbmss", "SpatDiv"))
library("magrittr")
# knitr options
knitr::opts_chunk$set(
cache = TRUE, # Cache chunk results
echo = TRUE, # Show R chunks
warning = FALSE, # Hide warnings
message = FALSE, # Hide warnings
fig.align='center', out.width='80%', fig.dim=c(7, 5),
# Code chunk format
tidy=TRUE, tidy.opts=list(blank=FALSE, width.cutoff=80)
)
# Random seed
set.seed(97310)
```
**SpatDiv** allows drawing random, spatialized communities as a whole, or species by species for more control.
# Drawing random communities
The function `rSpCommunity()` draws a community (which is a weighted, marked, planar point pattern, i.e. a `wmppp` object defined in package **dbmss**) or a list of communities (an `SpCommunities` object) if argument `n`, the number of communities, is greater than 1.
```{r DefaultSpCommunity, message=FALSE}
library("SpatDiv")
spCommunity <- rSpCommunity(1, size=30, S=5)
autoplot(spCommunity)
```
The random community obtained is made of 30 individuals in 5 species.
All arguments are set by default:
- The species distribution of abundances is lognormal.
It can be modified by the argument `Distribution`.
- The spatial window (argument `win`) is a square of side 1.
- The spatial distribution (argument `Spatial`) of each species is multinomial (i.e. point locations are independent, but their number is fixed).
- The species point patterns are independent.
- The size of all individuals (argument `Sizes`) is 1.
## Species abundances
Several species abundance distributions (SAD) are available:
- `Distribution = "lnorm"`: log-normal distribution with parameter `sd`, the standard deviation of the logarithm of probabilities.
The mean is forced by `size`, the number of individuals.
- `Distribution = "lseries"`: log-series distribution with parameter `alpha`.
- `Distribution = "geom"`: geometric distribution with parameter `prob`.
- `Distribution = "bstick"`: broken stick distribution.
## Individual size
The distribution of sizes is chosen by the argument `Sizes`:
- `Sizes = "Uniform"`: a uniform distribution between `MinSize` and `MaxSize`.
By default, `MinSize` and `MaxSize` equal 1 so all sizes are set to 1.
- `Sizes = "Exponential"`: a negative exponential distribution of rate $-1/MeanSize$.
- `Sizes = "Weibull"`: a Weibull distribution with parameters `shape` and `scale`.
`MinSize` is added (i.e., it is the location parameter of the Weibull distribution with three parameters).
# Drawing species separately
The function `rSpSpecies()` draws a single species spatial pattern, which is a a `wmppp` object.
```{r DefaultSpSpecies}
spSpecies <- rSpSpecies(50, Spatial = "Thomas", Sizes = "Exponential")
autoplot(spSpecies)
```
The point pattern of a a species is aggregated.
It follows a Thomas point process with default arguments.
Available point processes are:
- `Binomial`: points are draw independently like in a homogenous Poisson process but their number is forced to `n`.
- `Thomas`: points are clustered around centers whose density is `kappa`.
`mu` is the average number of points in each cluster.
`scale` is the standard deviation of the random displacement of points from the cluster centers.
More complex spatial distributions can be simulated in package **spatstat**.
`Spatial` can be an object of class `ppp` (a planar point pattern) obtained that way.
# Combining point patterns
Spatial communities stored in `wmppp` and `SpCommunities` objects can be superimposed by the `superimpose()` function from package **dbmss**.
```{r superimpose, message=FALSE}
library("dbmss")
superimpose(spSpecies, spCommunity) %>%
autoplot()
```
# References