Skip to content

Commit 5132aff

Browse files
committed
Day 2 ready
1 parent e7d9403 commit 5132aff

9 files changed

+173
-84
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Each day will consist of 3 sessions, roughly one hour each, with short breaks in
3333
| **Day 2** | **Behavioral complexities** | |
3434
| | 1. Statistical assumptions and nuisance variables | [Slides](https://peter.solymos.org/qpad-workshop/day2-1-intro.pdf) |
3535
| | 2. Behavioral complexities | [Notes](https://peter.solymos.org/qpad-workshop/day2-2-behavior.html) |
36-
| | 3. Removal modeling techniques 1. | [Notes](https://peter.solymos.org/qpad-workshop/day2-3-removal.html) |
37-
| | 3. Removal modeling techniques 2. | [Notes](https://peter.solymos.org/qpad-workshop/day2-3-mixtures.html) |
36+
| | 3. Removal modeling techniques | [Notes](https://peter.solymos.org/qpad-workshop/day2-3-removal.html) |
37+
| | 3. Finite mixture models | [Notes](https://peter.solymos.org/qpad-workshop/day2-4-mixtures.html) |
3838
| **Day 3** | **The detection process** | |
3939
| | 1. Distance sampling | |
4040
| | 2. Calibrating population density | |

day2-1-intro.Rmd

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Day 1
2828
Day 2
2929

3030
- Behavioral complexities
31+
- Removal models and assumptions
3132

3233
Day 3
3334

@@ -64,6 +65,16 @@ LOCAL copies will not be tracked and overwritten by git. You can copy new files
6465

6566
***
6667

68+
# Update bSims
69+
70+
Patched the Shiny apps, please update!
71+
72+
```{r eval=FALSE}
73+
remotes::install_github("psolymos/bSims")
74+
```
75+
76+
***
77+
6778
# What is detectability?
6879

6980
In the most colloquial terms, $\delta$ is the probability

day2-3-removal.Rmd

+19
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ We use the `fitdistr` function to fit an exponential distribution to these event
9191
```{r}
9292
phi <- 0.5
9393
(phi_hat <- fitdistr(v1$t, "exponential")$estimate)
94+
# which is the same as 1/mean(v1$t)
95+
1/mean(v1$t)
9496
```
9597

9698
The estimate is close to the true value of 0.5. Let's plot this
@@ -122,6 +124,23 @@ legend("bottomright", bty="n", lty=c(1,1,1,1), col=c(1,2,4,3),
122124
legend=c("Empirical", "Expected", "Estimated", "Binned"))
123125
```
124126

127+
Fitting survival model to the timt-to-event data
128+
129+
```{r}
130+
library(survival)
131+
t21 <- v1$t
132+
y01 <- ifelse(is.na(t21), 0, 1)
133+
## censoring at max when we have nondetections (not here but in general)
134+
t21[is.na(t21)] <- attr(v1, "tlim")[2]
135+
#time cannot be 0, so we use a small number instead
136+
t21[t21 == 0] <- 0.001
137+
## survival object
138+
sv <- Surv(t21, y01)
139+
m <- survreg(sv ~ 1, dist="exponential")
140+
1/exp(coef(m))
141+
```
142+
143+
125144
## Removal model
126145

127146
The time-removal model, originally developed for estimating wildlife and fish abundances from mark-recapture studies, was later reformulated for avian surveys with the goal of improving estimates of bird abundance by accounting for the availability bias inherent in point-count data. The removal model applied to point-count surveys estimates the probability that a bird is available for detection as a function of the average number of detectable cues that an individual bird gives per minute (singing rate, $\phi$), and the known count duration ($t$).

day2-4-mixtures.Rmd

+57-27
Original file line numberDiff line numberDiff line change
@@ -353,47 +353,77 @@ This result tells us mean abundance after correcting for availability bias, but
353353

354354
We'll address these problems next week. Let's just circle back to the assumptions.
355355

356+
## Exercise 1
356357

358+
What other mechanisms can lead to heterogeneity in behavior?
357359

360+
Use the `run_app("bsimsHER")` Shiny app to explore:
358361

362+
- find "edge cases"
363+
- copy `bsims_all()` calls from Shiny
359364

360-
## Further issues
361365

362-
Stratify the landscape, habitat related behavior (mixture)
366+
## Exercise 2
363367

364-
## Time to 1st detection info
368+
How does over/under counting influence estimated vocalization rates?
365369

366-
ARU, lots of hits, not always clear how many inds in recording
367-
Use tt1 (use the ABMI SM data set)
370+
(Hint: use the `perception` argument.)
368371

369-
## Methodological diffs
372+
```{r eval=FALSE}
373+
library(bSims)
370374
371-
ARU vs human on p
375+
phi <- 0.5
376+
B <- 10
377+
perc <- seq(0.5, 1.5, 0.1)
378+
379+
l <- expand_list(
380+
abund_fun = list(identity),
381+
duration = 10,
382+
vocal_rate = phi,
383+
tau = Inf,
384+
tint = list(c(3, 5, 10)),
385+
perception = perc)
386+
str(l[1:2])
387+
388+
## a list of bsims_all objects
389+
## $settings() $new(), $replicate(B, cl)
390+
b <- lapply(l, bsims_all)
391+
392+
## repeat the runs B times for each setting
393+
s <- lapply(b, function(z) {
394+
z$replicate(B, cl=4)
395+
})
396+
397+
## removal model
398+
phi_hat <- t(sapply(s, function(r) sapply(r, estimate)["phi",]))
399+
400+
matplot(perc, phi_hat, lty=1, type="l", col="grey", ylim=c(0, max(phi_hat)))
401+
lines(perc, apply(phi_hat, 1, median), lwd=2)
402+
abline(h=phi)
403+
404+
matplot(perc, 1-exp(-1*phi_hat), lty=1, type="l", col="grey", ylim=c(0,1))
405+
lines(perc, 1-exp(-1*apply(phi_hat, 1, median)), lwd=2)
406+
abline(h=1-exp(-1*phi), lty=2)
407+
```
372408

373-
## Std data ove time
409+
This is how perceived individual ID is deduced using locations:
374410

375-
TSSR/ JDAY effects, but migration?
411+
```{r eval=FALSE}
412+
set.seed(1)
413+
x <- bsims_all(density=0.1)$new()
414+
perception <- 0.75
376415
377-
## bSims/Shiny
416+
z <- get_events(x)
417+
z <- z[!duplicated(z$i),]
418+
dim(z)
419+
hc <- hclust(dist(cbind(z$x, z$y)), method="ward.D2")
378420
379-
We can collect all our settings into a `bsims_all` call
421+
h <- length(unique(z$i)) * perception
422+
z$j <- cutree(hc, k=min(nrow(z), max(1, round(h))))
380423
381-
```{r}
382-
xall <- bsims_all(
383-
extent=10,
384-
road=0.25, edge=0.5,
385-
density=c(1, 1, 0),
386-
vocal_rate=phi,
387-
move_rate=1, movement=0.2,
388-
tau=0.8,
389-
tint=c(3,5,10),
390-
rint=c(0.5, 1, 1.5))
391-
xall
424+
plot(hc)
425+
table(true=z$i, perceived=z$j)
426+
plot(z$x, z$y, pch=z$j, col=z$j)
392427
```
393428

394-
This call does not evaluate the expression, but it creates a 'closure' with all the info inside to create independent realizations (i.e. none of the layers will match across the runs)
395-
396-
```{r}
397-
xall$new()
398-
```
399429

docs/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Each day will consist of 3 sessions, roughly one hour each, with short breaks in
3333
| **Day 2** | **Behavioral complexities** | |
3434
| | 1. Statistical assumptions and nuisance variables | [Slides](https://peter.solymos.org/qpad-workshop/day2-1-intro.pdf) |
3535
| | 2. Behavioral complexities | [Notes](https://peter.solymos.org/qpad-workshop/day2-2-behavior.html) |
36-
| | 3. Removal modeling techniques 1. | [Notes](https://peter.solymos.org/qpad-workshop/day2-3-removal.html) |
37-
| | 3. Removal modeling techniques 2. | [Notes](https://peter.solymos.org/qpad-workshop/day2-3-mixtures.html) |
36+
| | 3. Removal modeling techniques | [Notes](https://peter.solymos.org/qpad-workshop/day2-3-removal.html) |
37+
| | 3. Finite mixture models | [Notes](https://peter.solymos.org/qpad-workshop/day2-4-mixtures.html) |
3838
| **Day 3** | **The detection process** | |
3939
| | 1. Distance sampling | |
4040
| | 2. Calibrating population density | |

docs/day2-1-intro.pdf

1.46 KB
Binary file not shown.

docs/day2-2-behavior.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ <h2>Prerequisites</h2>
405405
## of deldir() was changed to (simply) &quot;plot&quot;.
406406
##
407407
## See the help for deldir() and plot.deldir().</code></pre>
408-
<pre><code>## bSims 0.2-2 2019-12-17 ow-ow-ow-a-la</code></pre>
408+
<pre><code>## bSims 0.2-3 2021-03-15 kicky-chew</code></pre>
409409
<pre class="r"><code>library(detect) # multinomial models</code></pre>
410410
<pre><code>## Loading required package: Formula</code></pre>
411411
<pre><code>## Loading required package: stats4</code></pre>

docs/day2-3-removal.html

+18-1
Large diffs are not rendered by default.

docs/day2-4-mixtures.html

+63-51
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ <h4 class="author">Peter Solymos <a href="mailto:[email protected]" class="ema
384384
## of deldir() was changed to (simply) &quot;plot&quot;.
385385
##
386386
## See the help for deldir() and plot.deldir().</code></pre>
387-
<pre><code>## bSims 0.2-2 2019-12-17 ka-ka-ka-kowp-kowp-kowp</code></pre>
387+
<pre><code>## bSims 0.2-3 2021-03-15 chew-chew-chew</code></pre>
388388
<pre class="r"><code>library(detect) # multinomial models</code></pre>
389389
<pre><code>## Loading required package: Formula</code></pre>
390390
<pre><code>## Loading required package: stats4</code></pre>
@@ -785,57 +785,69 @@ <h2>Estimating abundance</h2>
785785
<p>This result tells us mean abundance after correcting for availability bias, but we don’t know what area was effectively sampled, and detection of individuals given availability is probably less than 1 because this happens to be a real data set and it is guaranteed that humans in the forest cannot detect birds that are very far (say &gt; 500 m away).</p>
786786
<p>We’ll address these problems next week. Let’s just circle back to the assumptions.</p>
787787
</div>
788-
<div id="further-issues" class="section level2">
789-
<h2>Further issues</h2>
790-
<p>Stratify the landscape, habitat related behavior (mixture)</p>
788+
<div id="exercise-1" class="section level2">
789+
<h2>Exercise 1</h2>
790+
<p>What other mechanisms can lead to heterogeneity in behavior?</p>
791+
<p>Use the <code>run_app(&quot;bsimsHER&quot;)</code> Shiny app to explore:</p>
792+
<ul>
793+
<li>find “edge cases”</li>
794+
<li>copy <code>bsims_all()</code> calls from Shiny</li>
795+
</ul>
791796
</div>
792-
<div id="time-to-1st-detection-info" class="section level2">
793-
<h2>Time to 1st detection info</h2>
794-
<p>ARU, lots of hits, not always clear how many inds in recording Use tt1 (use the ABMI SM data set)</p>
795-
</div>
796-
<div id="methodological-diffs" class="section level2">
797-
<h2>Methodological diffs</h2>
798-
<p>ARU vs human on p</p>
799-
</div>
800-
<div id="std-data-ove-time" class="section level2">
801-
<h2>Std data ove time</h2>
802-
<p>TSSR/ JDAY effects, but migration?</p>
803-
</div>
804-
<div id="bsimsshiny" class="section level2">
805-
<h2>bSims/Shiny</h2>
806-
<p>We can collect all our settings into a <code>bsims_all</code> call</p>
807-
<pre class="r"><code>xall &lt;- bsims_all(
808-
extent=10,
809-
road=0.25, edge=0.5,
810-
density=c(1, 1, 0),
811-
vocal_rate=phi,
812-
move_rate=1, movement=0.2,
813-
tau=0.8,
814-
tint=c(3,5,10),
815-
rint=c(0.5, 1, 1.5))
816-
xall</code></pre>
817-
<pre><code>## bSims wrapper object with settings:
818-
## extent : 10
819-
## road : 0.25
820-
## edge : 0.5
821-
## density : 1, 1, 0
822-
## vocal_rate: 0.5
823-
## move_rate : 1
824-
## movement : 0.2
825-
## tau : 0.8
826-
## tint : 3, 5, 10
827-
## rint : 0.5, 1, 1.5</code></pre>
828-
<p>This call does not evaluate the expression, but it creates a ‘closure’ with all the info inside to create independent realizations (i.e. none of the layers will match across the runs)</p>
829-
<pre class="r"><code>xall$new()</code></pre>
830-
<pre><code>## bSims transcript
831-
## 1 km x 1 km
832-
## stratification: HER
833-
## total abundance: 106
834-
## duration: 10 min
835-
## detected: 4 heard
836-
## 1st event detected by breaks:
837-
## [0, 3, 5, 10 min]
838-
## [0, 50, 100, 150 m]</code></pre>
797+
<div id="exercise-2" class="section level2">
798+
<h2>Exercise 2</h2>
799+
<p>How does over/under counting influence estimated vocalization rates?</p>
800+
<p>(Hint: use the <code>perception</code> argument.)</p>
801+
<pre class="r"><code>library(bSims)
802+
803+
phi &lt;- 0.5
804+
B &lt;- 10
805+
perc &lt;- seq(0.5, 1.5, 0.1)
806+
807+
l &lt;- expand_list(
808+
abund_fun = list(identity),
809+
duration = 10,
810+
vocal_rate = phi,
811+
tau = Inf,
812+
tint = list(c(3, 5, 10)),
813+
perception = perc)
814+
str(l[1:2])
815+
816+
## a list of bsims_all objects
817+
## $settings() $new(), $replicate(B, cl)
818+
b &lt;- lapply(l, bsims_all)
819+
820+
## repeat the runs B times for each setting
821+
s &lt;- lapply(b, function(z) {
822+
z$replicate(B, cl=4)
823+
})
824+
825+
## removal model
826+
phi_hat &lt;- t(sapply(s, function(r) sapply(r, estimate)[&quot;phi&quot;,]))
827+
828+
matplot(perc, phi_hat, lty=1, type=&quot;l&quot;, col=&quot;grey&quot;, ylim=c(0, max(phi_hat)))
829+
lines(perc, apply(phi_hat, 1, median), lwd=2)
830+
abline(h=phi)
831+
832+
matplot(perc, 1-exp(-1*phi_hat), lty=1, type=&quot;l&quot;, col=&quot;grey&quot;, ylim=c(0,1))
833+
lines(perc, 1-exp(-1*apply(phi_hat, 1, median)), lwd=2)
834+
abline(h=1-exp(-1*phi), lty=2)</code></pre>
835+
<p>This is how perceived individual ID is deduced using locations:</p>
836+
<pre class="r"><code>set.seed(1)
837+
x &lt;- bsims_all(density=0.1)$new()
838+
perception &lt;- 0.75
839+
840+
z &lt;- get_events(x)
841+
z &lt;- z[!duplicated(z$i),]
842+
dim(z)
843+
hc &lt;- hclust(dist(cbind(z$x, z$y)), method=&quot;ward.D2&quot;)
844+
845+
h &lt;- length(unique(z$i)) * perception
846+
z$j &lt;- cutree(hc, k=min(nrow(z), max(1, round(h))))
847+
848+
plot(hc)
849+
table(true=z$i, perceived=z$j)
850+
plot(z$x, z$y, pch=z$j, col=z$j)</code></pre>
839851
</div>
840852

841853

0 commit comments

Comments
 (0)