-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
171 lines (118 loc) · 4.21 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
output:
md_document:
variant: gfm
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
set.seed(0)
```
# bSims: Bird Point Count Simulator
<img src="https://raw.githubusercontent.com/psolymos/bSims/master/bsims.gif" align="right" style="padding-left:10px;background-color:white;" />
A highly scientific and utterly addictive bird point count simulator to test statistical assumptions and to aid survey design.
[![CRAN version](https://www.r-pkg.org/badges/version/bSims)](https://CRAN.R-project.org/package=bSims)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/bSims)](https://peter.solymos.org/bSims/)
[![check](https://github.com/psolymos/bSims/actions/workflows/check.yml/badge.svg)](https://github.com/psolymos/bSims/actions/workflows/check.yml)
> _"I've yet to see any problem, however complicated, which when you looked at it the right way didn't become still more complicated."_
> -- Poul Anderson, Call Me Joe
> *“Love the simulation we're dreaming in”* - Dua Lipa, Physical
The goal of the package is to:
- test statistical assumptions,
- aid survey design,
- and have fun while doing it!
Design objectives:
- small (point count) scale implementation,
- habitat is considered homogeneous except for edge effects,
- realistic but efficient implementation of biological mechanisms and observation process,
- defaults chosen to reflect common practice and assumptions,
- extensible (PRs are welcome).
See the package in action in the [**QPAD
Book**](https://peter.solymos.org/qpad-book/).
Check out the [**QPAD workshop**](https://peter.solymos.org/qpad-workshop/).
Read/cite the paper [**Agent-based simulations improve abundance estimation**](https://rdcu.be/doDwI) (DOI 10.1007/s42977-023-00183-2).
## Install
CRAN version:
```{r eval=FALSE}
install.packages("bSims")
```
Development version:
```{r eval=FALSE}
remotes::install_github("psolymos/bSims")
```
See what is new in the [NEWS](NEWS.md) file.
## License
[GPL-2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
Please cite (see `citation("bSims")`) the paper:
Solymos, P. 2023. Agent-based simulations improve abundance estimation. _Biologia Futura_ 74, 377--392 [DOI 10.1007/s42977-023-00183-2](https://doi.org/10.1007/s42977-023-00183-2), [link to PDF](https://rdcu.be/doDwI).
## Contributing
Feedback and contributions are welcome:
- submit feature request or report issues [here](https://github.com/psolymos/bSims/issues),
- fork the project and submit pull request, see [CoC](CODE_OF_CONDUCT.md).
## Examples
### Command line
```{r message=FALSE,warning=FALSE}
library(bSims)
phi <- 0.5
tau <- 1:3
dur <- 10
rbr <- c(0.5, 1, 1.5, Inf)
tbr <- c(3, 5, 10)
l <- bsims_init(10, 0.5, 1)
p <- bsims_populate(l, 1)
a <- bsims_animate(p, vocal_rate=phi, duration=dur)
o <- bsims_detect(a, tau=tau)
x <- bsims_transcribe(o, tint=tbr, rint=rbr)
get_table(x)
head(get_events(a))
head(get_detections(o))
```
### Shiny apps
A few [Shiny](https://shiny.posit.co/) apps come with the package.
These can be used to interactively explore the effects of different settings.
Compare distance functions:
```{r eval=FALSE}
run_app("distfunH")
run_app("distfunHER")
```
Compare simulation settings for single landscape:
```{r eval=FALSE}
run_app("bsimsH")
run_app("bsimsHER")
```
### Replicating simulations
Interactive sessions can be used to explore different settings.
Settings can be copied from the Shiny apps and replicated using the
`bsims_all` function:
```{r}
b <- bsims_all(extent=5, road=1, density=c(1,1,0))
b
```
The object has handy methods:
```{r eval=FALSE}
b$settings() # retrieve settings
b$new() # replicate once
b$replicate(10) # replicate 10x
```
The `$replicate()` function also runs on multiple cores:
```{r}
library(parallel)
b <- bsims_all(density=0.5)
B <- 4 # number of runs
nc <- 2 # number of cores
## sequential
system.time(bb <- b$replicate(B, cl=NULL))
## parallel clusters
cl <- makeCluster(nc)
## note: loading the package is optional
system.time(clusterEvalQ(cl, library(bSims)))
system.time(bb <- b$replicate(B, cl=cl))
stopCluster(cl)
## parallel forking
if (.Platform$OS.type != "windows") {
system.time(bb <- b$replicate(B, cl=nc))
}
```