<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/fitting-removal-models-with-the-detect-r-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://peter.solymos.org/code/2018/08/30/fitting-removal-models-with-the-detect-r-package.html"> Peter Solymos - R related posts</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In a paper recently published in the <a rel="nofollow" href="http://www.americanornithologypubs.org/" target="_blank">Condor</a>, titled <em>Evaluating time-removal models for estimating availability of boreal birds during point-count surveys: sample size requirements and model complexity</em>, we assessed different ways of controlling for point-count duration in bird counts using data from the <a rel="nofollow" href="http://www.borealbirds.ca/" target="_blank">Boreal Avian Modelling Project</a>. As the title indicates, the paper describes a cost-benefit analysis to make recommendations about when to use different types of the removal model. The paper is open access, so feel free to read the <a rel="nofollow" href="https://dx.doi.org/10.1650/CONDOR-18-32.1" target="_blank">whole paper here</a>).</p>
<p><img alt="Example species" src="https://i0.wp.com/peter.solymos.org/images/2018/08/30/example-species.png?w=456" data-recalc-dims="1"></p>
<p>In summary, we evaluated a conventional removal model and a finite mixture removal model, with and without covariates, for 152 bird species. We found that the probabilities of predicted availability under conventional and finite mixture models were very similar with respect to the range of probability values and the shape of the response curves to predictor variables. However, finite mixture models were better supported for the large majority of species. We also found overwhelming support for time-varying models irrespective of the parametrization.</p>
<p>I have wrote a related post about the journey that led to this paper (<a rel="nofollow" href="https://americanornithologypubsblog.org/2018/08/29/author-blog-count-me-in-i-am-available-for-detection-at-6-am-on-may-26th/" target="_blank"><em>Count me in! I am available for detection at 6 AM on May 26th</em></a>), in this post I describe the math behind the removal modeling as implemented in the <a rel="nofollow" href="https://cran.r-project.org/package=detect" target="_blank"><strong>detect</strong></a> <a rel="nofollow" href="https://r-project.org/" target="_blank">R</a> package.</p>
<h2>Continuous time-removal models</h2>
<p>It has long been recognized that nearly all avian field surveys underestimate abundances, unless the estimates are adjusted for the proportion of birds present but undetected at the times and locations surveyed. Detectability is the product of the probability that birds make themselves available for detection by emitting detectable cues (availability); and the probability that an available bird will be perceived by a bird surveyor (perceptibility).</p>
<p>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), and the known count duration.</p>
<p>Time-removal models are based on a removal experiment whereby animals are trapped and thereby removed from the closed population of animals being sampled. When applying a removal model to avian point-count surveys, the counts of singing birds () within a given point-count survey  () are tallied relative to when each bird is first detected in multiple and consecutive time intervals, with the survey start time , the end times of the time intervals  (), and the total count duration of the survey . We count each individual bird once, so individuals are â€˜mentally removed' from a closed population of undetected birds by the surveyor.</p>
<h2>Data requirements</h2>
<p>We have just defined the kind of data we need for the removal models. In this post, I am going to use a data set from our paper about comparing human observer based counts to automated recording units, <a rel="nofollow" href="https://doi.org/10.5751/ACE-00975-120113" target="_blank"><em>Paired sampling standardizes point count data from humans and acoustic recorders</em></a>. The data set we used is wrapped up in an R package called <a rel="nofollow" href="https://github.com/borealbirds/paired" target="_blank"><strong>paired</strong></a> (thanks for Steve Van Wilgenburg for suggestions on this post and for agreeing to share this data set).</p>
<div>
<div>
<pre><code><span>if</span><span> </span><span>(</span><span>!</span><span>require</span><span>(</span><span>paired</span><span>))</span><span>
</span><span>devtools</span><span>::</span><span>install_github</span><span>(</span><span>&quot;borealbirds/paired&quot;</span><span>)</span><span>
</span><span>library</span><span>(</span><span>paired</span><span>)</span><span>
</span><span>data</span><span>(</span><span>paired</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p>We will use the counts for Ovenbird, one of the most common species in the data set (abbreviated as <code>&quot;OVEN&quot;</code>). The data is in long format, so I am using the <a rel="nofollow" href="https://cran.r-project.org/package=mefa4" target="_blank"><strong>mefa4</strong></a> R package to make the sample by species cross-tabulation. Then subsetting the data to retain samples obtained by human observers, then getting rid of missing predictor data. For predictors, we will use a variable capturing date (<code>JDAY</code>; standardized ordinal day of the year) and an other one capturing time of day (<code>TSSR</code>; time since local sunrise).</p>
<p>The data frame <code>X</code> contains the predictors. The matrix <code>Y</code> contains the counts of newly counted individuals binned into consecutive time intervals (0 - 3, 3 - 5, 5 - 10 minutes): cell values are the 's. The <code>D</code> object is another matrix mirroring the structure of <code>Y</code><br>
but instead of counts, it contains the interval end times: cell values are<br>
the 's.</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>mefa4</span><span>)</span><span>
</span><span>spp</span><span> </span><span>&lt;-</span><span> </span><span>&quot;OVEN&quot;</span><span>
</span><span>xt</span><span> </span><span>&lt;-</span><span> </span><span>Xtab</span><span>(</span><span>Count</span><span> </span><span>~</span><span> </span><span>PKEY</span><span> </span><span>+</span><span> </span><span>Interval</span><span>,</span><span> </span><span>paired</span><span>,</span><span>
</span><span>subset</span><span>=</span><span>paired</span><span>$</span><span>SurveyType</span><span> </span><span>==</span><span> </span><span>&quot;HUM&quot;</span><span> </span><span>&amp;</span><span> </span><span>paired</span><span>$</span><span>SPECIES</span><span> </span><span>==</span><span> </span><span>spp</span><span>)</span><span>
</span><span>Y</span><span> </span><span>&lt;-</span><span> </span><span>as.matrix</span><span>(</span><span>xt</span><span>[,</span><span>c</span><span>(</span><span>&quot;0-3 min&quot;</span><span>,</span><span> </span><span>&quot;3-5 min&quot;</span><span>,</span><span> </span><span>&quot;5-10 min&quot;</span><span>)])</span><span>
</span><span>X</span><span> </span><span>&lt;-</span><span> </span><span>nonDuplicated</span><span>(</span><span>paired</span><span>[</span><span>paired</span><span>$</span><span>SurveyType</span><span> </span><span>==</span><span> </span><span>&quot;HUM&quot;</span><span>,],</span><span>
</span><span>PKEY</span><span>,</span><span> </span><span>TRUE</span><span>)[</span><span>rownames</span><span>(</span><span>Y</span><span>),]</span><span>
</span><span>i</span><span> </span><span>&lt;-</span><span> </span><span>!</span><span>is.na</span><span>(</span><span>X</span><span>$</span><span>Latitude</span><span>)</span><span>
</span><span>Y</span><span> </span><span>&lt;-</span><span> </span><span>Y</span><span>[</span><span>i</span><span>,]</span><span>
</span><span>X</span><span> </span><span>&lt;-</span><span> </span><span>X</span><span>[</span><span>i</span><span>,</span><span>c</span><span>(</span><span>&quot;JDAY&quot;</span><span>,</span><span> </span><span>&quot;TSSR&quot;</span><span>)]</span><span>
</span><span>D</span><span> </span><span>&lt;-</span><span> </span><span>matrix</span><span>(</span><span>c</span><span>(</span><span>3</span><span>,</span><span> </span><span>5</span><span>,</span><span> </span><span>10</span><span>),</span><span> </span><span>nrow</span><span>(</span><span>Y</span><span>),</span><span> </span><span>3</span><span>,</span><span> </span><span>byrow</span><span>=</span><span>TRUE</span><span>)</span><span>
</span><span>dimnames</span><span>(</span><span>D</span><span>)</span><span> </span><span>&lt;-</span><span> </span><span>dimnames</span><span>(</span><span>Y</span><span>)</span><span>
</span><span>tail</span><span>(</span><span>X</span><span>)</span><span>
</span><span>## JDAY TSSR</span><span>
</span><span>## 96PA-C2-B_2 0.4383562 0.13468851</span><span>
</span><span>## 96PA-C2-C_1 0.4438356 0.08526145</span><span>
</span><span>## 96PA-C2-C_2 0.4383562 0.15273704</span><span>
</span><span>## 96PA-C2-D_1 0.4438356 0.13597129</span><span>
</span><span>## 96PA-C2-E_1 0.4438356 0.10122629</span><span>
</span><span>## 96PA-C2-F_1 0.4438356 0.11999388</span><span>
</span><span>tail</span><span>(</span><span>Y</span><span>)</span><span>
</span><span>## 0-3 min 3-5 min 5-10 min</span><span>
</span><span>## 96PA-C2-B_2 5 0 0</span><span>
</span><span>## 96PA-C2-C_1 2 0 0</span><span>
</span><span>## 96PA-C2-C_2 2 0 0</span><span>
</span><span>## 96PA-C2-D_1 7 0 0</span><span>
</span><span>## 96PA-C2-E_1 2 0 0</span><span>
</span><span>## 96PA-C2-F_1 2 0 0</span><span>
</span><span>tail</span><span>(</span><span>D</span><span>)</span><span>
</span><span>0-3</span><span> </span><span>min</span><span> </span><span>3-5</span><span> </span><span>min</span><span> </span><span>5-10</span><span> </span><span>min</span><span>
</span><span>## 96PA-C2-B_2 3 5 10</span><span>
</span><span>## 96PA-C2-C_1 3 5 10</span><span>
</span><span>## 96PA-C2-C_2 3 5 10</span><span>
</span><span>## 96PA-C2-D_1 3 5 10</span><span>
</span><span>## 96PA-C2-E_1 3 5 10</span><span>
</span><span>## 96PA-C2-F_1 3 5 10</span><span>
</span></code></pre>
</div>
</div>
<h2>Time-invariant conventional removal model</h2>
<p>In the simplest continuous time-removal model, singing events by individual birds are assumed to follow a Poisson process. We can use the rate parameter of the Poisson process () to estimate the singing rate of birds during a point count.</p>
<p>In the time-invariant conventional removal model (<code>Me0</code>), the individuals of a species at a given location and time are assumed to be homogeneous in their singing rates. The time to first detection follows the exponential distribution , and the cumulative density function of times to first detection in time interval (0, ) gives us the probability that a bird sings at least once during the point count as .</p>
<p>We use the <code>cmulti</code> function from the <strong>detect</strong> R package to fit the removal models. The algorithm used in the function is based on conditional maximum likelihood, and is described in <a rel="nofollow" href="http://dx.doi.org/10.1111/2041-210X.12106" target="_blank">this paper</a> its <a rel="nofollow" href="https://github.com/psolymos/QPAD/tree/master/inst/doc/v2" target="_blank">supporting material</a>.<br>
We are using the <code>type = &quot;rem&quot;</code> for conventional removal models.</p>
<div>
<div>
<pre><code><span>library</span><span>(</span><span>detect</span><span>)</span><span>
</span><span>Me0</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>1</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;rem&quot;</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>Me0</span><span>)</span><span>
</span><span>## Call:</span><span>
</span><span>## cmulti(formula = Y | D ~ 1, data = X, type = &quot;rem&quot;)</span><span>
</span><span>##</span><span>
</span><span>## Removal Sampling (homogeneous singing rate)</span><span>
</span><span>## Conditional Maximum Likelihood estimates</span><span>
</span><span>##</span><span>
</span><span>## Coefficients:</span><span>
</span><span>## Estimate Std. Error z value Pr(>|z|)</span><span>
</span><span>## log.phi_(Intercept) -0.91751 0.05826 -15.75 &lt;2e-16 ***</span><span>
</span><span>## ---</span><span>
</span><span>## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span><span>
</span><span>##</span><span>
</span><span>## Log-likelihood: -272.1</span><span>
</span><span>## BIC = 549.4</span><span>
</span></code></pre>
</div>
</div>
<h2>Time-varying conventional removal models</h2>
<p>Singing rates of birds vary with time of day, time of year, breeding status, and stage of the nesting cycle. Thus, removal model estimates of availability may be improved by accounting for variation in singing rates using covariates for day of year and time of day. In this case  and  is the linear predictor with  covariates and the corresponding unknown coefficients (, ).</p>
<p>We could fit all the possible multivariate and nonlinear models as we did in the paper, but<br>
let's just keep it simple for now and fit models with <code>JDAY</code> and <code>TSSR</code> as covariates<br>
(models <code>Me1</code> and <code>Me2</code>).</p>
<div>
<div>
<pre><code><span>Me1</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>JDAY</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;rem&quot;</span><span>)</span><span>
</span><span>Me2</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>TSSR</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;rem&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p>Now compare the three conventional models based on AIC and inspect the summary for the best supported model with the <code>JDAY</code> effect.</p>
<div>
<div>
<pre><code><span>Me_AIC</span><span> </span><span>&lt;-</span><span> </span><span>AIC</span><span>(</span><span>Me0</span><span>,</span><span> </span><span>Me1</span><span>,</span><span> </span><span>Me2</span><span>)</span><span>
</span><span>Me_AIC</span><span>$</span><span>dAIC</span><span> </span><span>&lt;-</span><span> </span><span>Me_AIC</span><span>$</span><span>AIC</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>Me_AIC</span><span>$</span><span>AIC</span><span>)</span><span>
</span><span>MeBest</span><span> </span><span>&lt;-</span><span> </span><span>get</span><span>(</span><span>rownames</span><span>(</span><span>Me_AIC</span><span>)[</span><span>Me_AIC</span><span>$</span><span>dAIC</span><span> </span><span>==</span><span> </span><span>0</span><span>])</span><span>
</span><span>Me_AIC</span><span>
</span><span>## df AIC dAIC</span><span>
</span><span>## Me0 1 546.1270 0.7187895</span><span>
</span><span>## Me1 2 545.4082 0.0000000</span><span>
</span><span>## Me2 2 546.4612 1.0529236</span><span>
</span><span>summary</span><span>(</span><span>MeBest</span><span>)</span><span>
</span><span>## Call:</span><span>
</span><span>## cmulti(formula = Y | D ~ JDAY, data = X, type = &quot;rem&quot;)</span><span>
</span><span>##</span><span>
</span><span>## Removal Sampling (homogeneous singing rate)</span><span>
</span><span>## Conditional Maximum Likelihood estimates</span><span>
</span><span>##</span><span>
</span><span>## Coefficients:</span><span>
</span><span>## Estimate Std. Error z value Pr(>|z|)</span><span>
</span><span>## log.phi_(Intercept) 1.460 1.471 0.993 0.321</span><span>
</span><span>## log.phi_JDAY -5.235 3.247 -1.612 0.107</span><span>
</span><span>##</span><span>
</span><span>## Log-likelihood: -270.7</span><span>
</span><span>## BIC = 552</span><span>
</span></code></pre>
</div>
</div>
<p>To visually capture the time-varying effects, we make some plots using base graphics, colors matching the time-varying predictor. This way we can not only assess how availability probability (given a fixed time interval) is changing with the values of the predictor, but also how the cumulative distribution changes with time.</p>
<div>
<div>
<pre><code><span>n</span><span> </span><span>&lt;-</span><span> </span><span>100</span><span>
</span><span>JDAY</span><span> </span><span>&lt;-</span><span> </span><span>seq</span><span>(</span><span>min</span><span>(</span><span>X</span><span>$</span><span>JDAY</span><span>),</span><span> </span><span>max</span><span>(</span><span>X</span><span>$</span><span>JDAY</span><span>),</span><span> </span><span>length.out</span><span>=</span><span>n</span><span>+1</span><span>)</span><span>
</span><span>TSSR</span><span> </span><span>&lt;-</span><span> </span><span>seq</span><span>(</span><span>min</span><span>(</span><span>X</span><span>$</span><span>TSSR</span><span>),</span><span> </span><span>max</span><span>(</span><span>X</span><span>$</span><span>TSSR</span><span>),</span><span> </span><span>length.out</span><span>=</span><span>n</span><span>+1</span><span>)</span><span>
</span><span>Duration</span><span> </span><span>&lt;-</span><span> </span><span>seq</span><span>(</span><span>0</span><span>,</span><span> </span><span>10</span><span>,</span><span> </span><span>length.out</span><span>=</span><span>n</span><span>)</span><span>
</span><span>col</span><span> </span><span>&lt;-</span><span> </span><span>viridis</span><span>::</span><span>viridis</span><span>(</span><span>n</span><span>)</span><span>
</span><span>b</span><span> </span><span>&lt;-</span><span> </span><span>coef</span><span>(</span><span>MeBest</span><span>)</span><span>
</span><span>op</span><span> </span><span>&lt;-</span><span> </span><span>par</span><span>(</span><span>las</span><span>=</span><span>1</span><span>,</span><span> </span><span>mfrow</span><span>=</span><span>c</span><span>(</span><span>2</span><span>,</span><span>1</span><span>),</span><span> </span><span>mar</span><span>=</span><span>c</span><span>(</span><span>4</span><span>,</span><span>4</span><span>,</span><span>2</span><span>,</span><span>2</span><span>))</span><span>
</span><span>p</span><span>1</span><span> </span><span>&lt;-</span><span> </span><span>1</span><span>-</span><span>exp</span><span>(</span><span>-3</span><span>*</span><span>exp</span><span>(</span><span>b</span><span>[</span><span>1</span><span>]</span><span>+</span><span>b</span><span>[</span><span>2</span><span>]</span><span>*</span><span>JDAY</span><span>))</span><span>
</span><span>plot</span><span>(</span><span>JDAY</span><span>,</span><span> </span><span>p</span><span>1</span><span>,</span><span> </span><span>ylim</span><span>=</span><span>c</span><span>(</span><span>0</span><span>,</span><span>1</span><span>),</span><span> </span><span>type</span><span>=</span><span>&quot;n&quot;</span><span>,</span><span>
</span><span>main</span><span>=</span><span>paste</span><span>(</span><span>spp</span><span>,</span><span> </span><span>rownames</span><span>(</span><span>Me_AIC</span><span>)[</span><span>Me_AIC</span><span>$</span><span>dAIC</span><span> </span><span>==</span><span> </span><span>0</span><span>]),</span><span>
</span><span>ylab</span><span>=</span><span>&quot;P(availability)&quot;</span><span>)</span><span>
</span><span>for</span><span> </span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>seq_len</span><span>(</span><span>n</span><span>))</span><span> </span><span>{</span><span>
</span><span>lines</span><span>(</span><span>JDAY</span><span>[</span><span>c</span><span>(</span><span>i</span><span>,</span><span>i</span><span>+1</span><span>)],</span><span> </span><span>p</span><span>1</span><span>[</span><span>c</span><span>(</span><span>i</span><span>,</span><span>i</span><span>+1</span><span>)],</span><span> </span><span>col</span><span>=</span><span>col</span><span>[</span><span>i</span><span>],</span><span> </span><span>lwd</span><span>=</span><span>2</span><span>)</span><span>
</span><span>}</span><span>
</span><span>plot</span><span>(</span><span>Duration</span><span>,</span><span> </span><span>Duration</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;n&quot;</span><span>,</span><span> </span><span>ylim</span><span>=</span><span>c</span><span>(</span><span>0</span><span>,</span><span>1</span><span>),</span><span>
</span><span>ylab</span><span>=</span><span>&quot;P(availability)&quot;</span><span>)</span><span>
</span><span>for</span><span> </span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>seq_len</span><span>(</span><span>n</span><span>))</span><span> </span><span>{</span><span>
</span><span>p</span><span>2</span><span> </span><span>&lt;-</span><span> </span><span>1</span><span>-</span><span>exp</span><span>(</span><span>-</span><span>Duration</span><span>*</span><span>exp</span><span>(</span><span>b</span><span>[</span><span>1</span><span>]</span><span>+</span><span>b</span><span>[</span><span>2</span><span>]</span><span>*</span><span>JDAY</span><span>[</span><span>i</span><span>]))</span><span>
</span><span>lines</span><span>(</span><span>Duration</span><span>,</span><span> </span><span>p</span><span>2</span><span>,</span><span> </span><span>col</span><span>=</span><span>col</span><span>[</span><span>i</span><span>])</span><span>
</span><span>}</span><span>
</span><span>abline</span><span>(</span><span>v</span><span>=</span><span>3</span><span>,</span><span> </span><span>col</span><span>=</span><span>&quot;grey&quot;</span><span>)</span><span>
</span><span>par</span><span>(</span><span>op</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p><img alt="Me model predictions" src="https://i1.wp.com/peter.solymos.org/images/2018/08/30/MePlot.png?w=456" data-recalc-dims="1"></p>
<h2>Time-invariant finite mixture removal model</h2>
<p>The removal model can also accommodate behavioral heterogeneity in singing by subdividing the sampled population for a species at a given point into a finite mixture of birds with low and high singing rates, which requires the additional estimation of the proportion of birds in the sampled population with low singing rates.</p>
<p>In the continuous-time formulation of the finite mixture (or two-point mixture) removal model, the cumulative density function during a point count is given by , where  is the singing rate for the group of infrequently singing birds, and  is the proportion of birds during the point count that are infrequent singers. The remaining proportions (; the intercept of the cumulative density function) of the frequent singers are assumed to be detected instantaneously at the start of the first time interval. In the simplest form of the finite mixture model, the proportion and singing rate of birds that sing infrequently is homogeneous across all times and locations (model <code>Mf0</code>). We are using the <code>type = &quot;fmix&quot;</code> for finite mixture removal models.</p>
<div>
<div>
<pre><code><span>Mf0</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>1</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;fmix&quot;</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>Mf0</span><span>)</span><span>
</span><span>## Call:</span><span>
</span><span>## cmulti(formula = Y | D ~ 1, data = X, type = &quot;fmix&quot;)</span><span>
</span><span>##</span><span>
</span><span>## Removal Sampling (heterogeneous singing rate)</span><span>
</span><span>## Conditional Maximum Likelihood estimates</span><span>
</span><span>##</span><span>
</span><span>## Coefficients:</span><span>
</span><span>## Estimate Std. Error z value Pr(>|z|)</span><span>
</span><span>## log.phi_(Intercept) -2.1902 0.4914 -4.457 8.32e-06 ***</span><span>
</span><span>## logit.c 0.1182 0.1543 0.766 0.444</span><span>
</span><span>## ---</span><span>
</span><span>## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span><span>
</span><span>##</span><span>
</span><span>## Log-likelihood: -257.6</span><span>
</span><span>## BIC = 525.8</span><span>
</span></code></pre>
</div>
</div>
<h2>Time-varying finite mixture removal models</h2>
<p>Previously, researchers (see refs in the paper) have applied covariate effects on the parameter  of the finite mixture model, similarly to how we modeled these effects in conventional models. This model assumes that the parameter  is constant irrespective of time and location (i.e. only the infrequent singer group changes its singing behavior).</p>
<p>We can fit finite mixture models with <code>JDAY</code> and <code>TSSR</code> as covariates on <br>
(models <code>Mf1</code> and <code>Mf2</code>). In this case  and  is the linear predictor with  covariates and the corresponding unknown coefficients (, ).</p>
<div>
<div>
<pre><code><span>Mf1</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>JDAY</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;fmix&quot;</span><span>)</span><span>
</span><span>Mf2</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>TSSR</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;fmix&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p>Compare the three finite mixture models based on AIC and inspect the summary for the best supported model with the <code>TSSR</code> effect in this case.</p>
<div>
<div>
<pre><code><span>Mf_AIC</span><span> </span><span>&lt;-</span><span> </span><span>AIC</span><span>(</span><span>Mf0</span><span>,</span><span> </span><span>Mf1</span><span>,</span><span> </span><span>Mf2</span><span>)</span><span>
</span><span>Mf_AIC</span><span>$</span><span>dAIC</span><span> </span><span>&lt;-</span><span> </span><span>Mf_AIC</span><span>$</span><span>AIC</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>Mf_AIC</span><span>$</span><span>AIC</span><span>)</span><span>
</span><span>MfBest</span><span> </span><span>&lt;-</span><span> </span><span>get</span><span>(</span><span>rownames</span><span>(</span><span>Mf_AIC</span><span>)[</span><span>Mf_AIC</span><span>$</span><span>dAIC</span><span> </span><span>==</span><span> </span><span>0</span><span>])</span><span>
</span><span>Mf_AIC</span><span>
</span><span>## df AIC dAIC</span><span>
</span><span>## Mf0 2 519.2222 0.1053855</span><span>
</span><span>## Mf1 3 520.4007 1.2838985</span><span>
</span><span>## Mf2 3 519.1168 0.0000000</span><span>
</span><span>summary</span><span>(</span><span>MfBest</span><span>)</span><span>
</span><span>## Call:</span><span>
</span><span>## cmulti(formula = Y | D ~ TSSR, data = X, type = &quot;fmix&quot;)</span><span>
</span><span>##</span><span>
</span><span>## Removal Sampling (heterogeneous singing rate)</span><span>
</span><span>## Conditional Maximum Likelihood estimates</span><span>
</span><span>##</span><span>
</span><span>## Coefficients:</span><span>
</span><span>## Estimate Std. Error z value Pr(>|z|)</span><span>
</span><span>## log.phi_(Intercept) -1.1939 0.4195 -2.846 0.00442 **</span><span>
</span><span>## log.phi_TSSR -9.0089 4.7712 -1.888 0.05900 .</span><span>
</span><span>## logit.c 0.2016 0.1702 1.184 0.23622</span><span>
</span><span>## ---</span><span>
</span><span>## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span><span>
</span><span>##</span><span>
</span><span>## Log-likelihood: -256.6</span><span>
</span><span>## BIC = 529</span><span>
</span></code></pre>
</div>
</div>
<p>We produce a similar plot as before.</p>
<div>
<div>
<pre><code><span>b</span><span> </span><span>&lt;-</span><span> </span><span>coef</span><span>(</span><span>MfBest</span><span>)</span><span>
</span><span>op</span><span> </span><span>&lt;-</span><span> </span><span>par</span><span>(</span><span>las</span><span>=</span><span>1</span><span>,</span><span> </span><span>mfrow</span><span>=</span><span>c</span><span>(</span><span>2</span><span>,</span><span>1</span><span>),</span><span> </span><span>mar</span><span>=</span><span>c</span><span>(</span><span>4</span><span>,</span><span>4</span><span>,</span><span>2</span><span>,</span><span>2</span><span>))</span><span>
</span><span>p</span><span>1</span><span> </span><span>&lt;-</span><span> </span><span>1</span><span>-</span><span>plogis</span><span>(</span><span>b</span><span>[</span><span>3</span><span>])</span><span>*</span><span>exp</span><span>(</span><span>-3</span><span>*</span><span>exp</span><span>(</span><span>b</span><span>[</span><span>1</span><span>]</span><span>+</span><span>b</span><span>[</span><span>2</span><span>]</span><span>*</span><span>TSSR</span><span>))</span><span>
</span><span>plot</span><span>(</span><span>TSSR</span><span>,</span><span> </span><span>p</span><span>1</span><span>,</span><span> </span><span>ylim</span><span>=</span><span>c</span><span>(</span><span>0</span><span>,</span><span>1</span><span>),</span><span> </span><span>type</span><span>=</span><span>&quot;n&quot;</span><span>,</span><span>
</span><span>main</span><span>=</span><span>paste</span><span>(</span><span>spp</span><span>,</span><span> </span><span>rownames</span><span>(</span><span>Mf_AIC</span><span>)[</span><span>Mf_AIC</span><span>$</span><span>dAIC</span><span> </span><span>==</span><span> </span><span>0</span><span>]),</span><span>
</span><span>ylab</span><span>=</span><span>&quot;P(availability)&quot;</span><span>)</span><span>
</span><span>for</span><span> </span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>seq_len</span><span>(</span><span>n</span><span>))</span><span> </span><span>{</span><span>
</span><span>lines</span><span>(</span><span>TSSR</span><span>[</span><span>c</span><span>(</span><span>i</span><span>,</span><span>i</span><span>+1</span><span>)],</span><span> </span><span>p</span><span>1</span><span>[</span><span>c</span><span>(</span><span>i</span><span>,</span><span>i</span><span>+1</span><span>)],</span><span> </span><span>col</span><span>=</span><span>col</span><span>[</span><span>i</span><span>],</span><span> </span><span>lwd</span><span>=</span><span>2</span><span>)</span><span>
</span><span>}</span><span>
</span><span>plot</span><span>(</span><span>Duration</span><span>,</span><span> </span><span>Duration</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;n&quot;</span><span>,</span><span> </span><span>ylim</span><span>=</span><span>c</span><span>(</span><span>0</span><span>,</span><span>1</span><span>),</span><span>
</span><span>ylab</span><span>=</span><span>&quot;P(availability)&quot;</span><span>)</span><span>
</span><span>for</span><span> </span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>seq_len</span><span>(</span><span>n</span><span>))</span><span> </span><span>{</span><span>
</span><span>p</span><span>2</span><span> </span><span>&lt;-</span><span> </span><span>1</span><span>-</span><span>plogis</span><span>(</span><span>b</span><span>[</span><span>3</span><span>])</span><span>*</span><span>exp</span><span>(</span><span>-</span><span>Duration</span><span>*</span><span>exp</span><span>(</span><span>b</span><span>[</span><span>1</span><span>]</span><span>+</span><span>b</span><span>[</span><span>2</span><span>]</span><span>*</span><span>TSSR</span><span>[</span><span>i</span><span>]))</span><span>
</span><span>lines</span><span>(</span><span>Duration</span><span>,</span><span> </span><span>p</span><span>2</span><span>,</span><span> </span><span>col</span><span>=</span><span>col</span><span>[</span><span>i</span><span>])</span><span>
</span><span>}</span><span>
</span><span>abline</span><span>(</span><span>v</span><span>=</span><span>3</span><span>,</span><span> </span><span>col</span><span>=</span><span>&quot;grey&quot;</span><span>)</span><span>
</span><span>par</span><span>(</span><span>op</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p><img alt="Me model predictions" src="https://i2.wp.com/peter.solymos.org/images/2018/08/30/MfPlot.png?w=456" data-recalc-dims="1"></p>
<p>An alternative parametrization is that  rather than  be the time-varying parameter, allowing the individuals to switch between the frequent and infrequent group depending on covariates. We can fit this class of finite mixture model with <code>JDAY</code> and <code>TSSR</code> as covariates on  (models <code>Mm1</code> and <code>Mm2</code>) using <code>type = &quot;mix&quot;</code> (instead of <code>&quot;fmix&quot;</code>). In this case  and  is the linear predictor with  covariates and the corresponding unknown coefficients (, ). Because  is a proportion, we model it on the logit scale.</p>
<div>
<div>
<pre><code><span>Mm1</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>JDAY</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;mix&quot;</span><span>)</span><span>
</span><span>Mm2</span><span> </span><span>&lt;-</span><span> </span><span>cmulti</span><span>(</span><span>Y</span><span> </span><span>|</span><span> </span><span>D</span><span> </span><span>~</span><span> </span><span>TSSR</span><span>,</span><span> </span><span>X</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;mix&quot;</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p>We did not fit a null model for this parametrization, because it is identical to the <code>Mf0</code> model, so that model <code>Mf0</code> is what we use to compare AIC values and inspect the summary for the best supported model with the <code>JDAY</code> effect in this case.</p>
<div>
<div>
<pre><code><span>Mm_AIC</span><span> </span><span>&lt;-</span><span> </span><span>AIC</span><span>(</span><span>Mf0</span><span>,</span><span> </span><span>Mm1</span><span>,</span><span> </span><span>Mm2</span><span>)</span><span>
</span><span>Mm_AIC</span><span>$</span><span>dAIC</span><span> </span><span>&lt;-</span><span> </span><span>Mm_AIC</span><span>$</span><span>AIC</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>Mm_AIC</span><span>$</span><span>AIC</span><span>)</span><span>
</span><span>MmBest</span><span> </span><span>&lt;-</span><span> </span><span>get</span><span>(</span><span>rownames</span><span>(</span><span>Mm_AIC</span><span>)[</span><span>Mm_AIC</span><span>$</span><span>dAIC</span><span> </span><span>==</span><span> </span><span>0</span><span>])</span><span>
</span><span>Mm_AIC</span><span>
</span><span>## df AIC dAIC</span><span>
</span><span>## Mf0 2 519.2222 0.1949952</span><span>
</span><span>## Mm1 3 519.0272 0.0000000</span><span>
</span><span>## Mm2 3 520.8744 1.8471803</span><span>
</span><span>summary</span><span>(</span><span>MmBest</span><span>)</span><span>
</span><span>## Call:</span><span>
</span><span>## cmulti(formula = Y | D ~ JDAY, data = X, type = &quot;mix&quot;)</span><span>
</span><span>##</span><span>
</span><span>## Removal Sampling (heterogeneous singing rate)</span><span>
</span><span>## Conditional Maximum Likelihood estimates</span><span>
</span><span>##</span><span>
</span><span>## Coefficients:</span><span>
</span><span>## Estimate Std. Error z value Pr(>|z|)</span><span>
</span><span>## log.phi -2.1910 0.4914 -4.459 8.24e-06 ***</span><span>
</span><span>## logit.c_(Intercept) -4.7600 3.3828 -1.407 0.159</span><span>
</span><span>## logit.c_JDAY 10.7368 7.4287 1.445 0.148</span><span>
</span><span>## ---</span><span>
</span><span>## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1</span><span>
</span><span>##</span><span>
</span><span>## Log-likelihood: -256.5</span><span>
</span><span>## BIC = 528.9</span><span>
</span></code></pre>
</div>
</div>
<p>We produce a similar plot as before.</p>
<div>
<div>
<pre><code><span>b</span><span> </span><span>&lt;-</span><span> </span><span>coef</span><span>(</span><span>MmBest</span><span>)</span><span>
</span><span>op</span><span> </span><span>&lt;-</span><span> </span><span>par</span><span>(</span><span>las</span><span>=</span><span>1</span><span>,</span><span> </span><span>mfrow</span><span>=</span><span>c</span><span>(</span><span>2</span><span>,</span><span>1</span><span>),</span><span> </span><span>mar</span><span>=</span><span>c</span><span>(</span><span>4</span><span>,</span><span>4</span><span>,</span><span>2</span><span>,</span><span>2</span><span>))</span><span>
</span><span>p</span><span>1</span><span> </span><span>&lt;-</span><span> </span><span>1</span><span>-</span><span>plogis</span><span>(</span><span>b</span><span>[</span><span>2</span><span>]</span><span>+</span><span>b</span><span>[</span><span>3</span><span>]</span><span>*</span><span>JDAY</span><span>)</span><span>*</span><span>exp</span><span>(</span><span>-3</span><span>*</span><span>exp</span><span>(</span><span>b</span><span>[</span><span>1</span><span>]))</span><span>
</span><span>plot</span><span>(</span><span>JDAY</span><span>,</span><span> </span><span>p</span><span>1</span><span>,</span><span> </span><span>ylim</span><span>=</span><span>c</span><span>(</span><span>0</span><span>,</span><span>1</span><span>),</span><span> </span><span>type</span><span>=</span><span>&quot;n&quot;</span><span>,</span><span>
</span><span>main</span><span>=</span><span>paste</span><span>(</span><span>spp</span><span>,</span><span> </span><span>rownames</span><span>(</span><span>Mm_AIC</span><span>)[</span><span>Mm_AIC</span><span>$</span><span>dAIC</span><span> </span><span>==</span><span> </span><span>0</span><span>]),</span><span>
</span><span>ylab</span><span>=</span><span>&quot;P(availability)&quot;</span><span>)</span><span>
</span><span>for</span><span> </span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>seq_len</span><span>(</span><span>n</span><span>))</span><span> </span><span>{</span><span>
</span><span>lines</span><span>(</span><span>JDAY</span><span>[</span><span>c</span><span>(</span><span>i</span><span>,</span><span>i</span><span>+1</span><span>)],</span><span> </span><span>p</span><span>1</span><span>[</span><span>c</span><span>(</span><span>i</span><span>,</span><span>i</span><span>+1</span><span>)],</span><span> </span><span>col</span><span>=</span><span>col</span><span>[</span><span>i</span><span>],</span><span> </span><span>lwd</span><span>=</span><span>2</span><span>)</span><span>
</span><span>}</span><span>
</span><span>plot</span><span>(</span><span>Duration</span><span>,</span><span> </span><span>Duration</span><span>,</span><span> </span><span>type</span><span>=</span><span>&quot;n&quot;</span><span>,</span><span> </span><span>ylim</span><span>=</span><span>c</span><span>(</span><span>0</span><span>,</span><span>1</span><span>),</span><span>
</span><span>ylab</span><span>=</span><span>&quot;P(availability)&quot;</span><span>)</span><span>
</span><span>for</span><span> </span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>seq_len</span><span>(</span><span>n</span><span>))</span><span> </span><span>{</span><span>
</span><span>p</span><span>2</span><span> </span><span>&lt;-</span><span> </span><span>1</span><span>-</span><span>plogis</span><span>(</span><span>b</span><span>[</span><span>2</span><span>]</span><span>+</span><span>b</span><span>[</span><span>3</span><span>]</span><span>*</span><span>JDAY</span><span>[</span><span>i</span><span>])</span><span>*</span><span>exp</span><span>(</span><span>-</span><span>Duration</span><span>*</span><span>exp</span><span>(</span><span>b</span><span>[</span><span>1</span><span>]))</span><span>
</span><span>lines</span><span>(</span><span>Duration</span><span>,</span><span> </span><span>p</span><span>2</span><span>,</span><span> </span><span>col</span><span>=</span><span>col</span><span>[</span><span>i</span><span>])</span><span>
</span><span>}</span><span>
</span><span>abline</span><span>(</span><span>v</span><span>=</span><span>3</span><span>,</span><span> </span><span>col</span><span>=</span><span>&quot;grey&quot;</span><span>)</span><span>
</span><span>par</span><span>(</span><span>op</span><span>)</span><span>
</span></code></pre>
</div>
</div>
<p><img alt="Me model predictions" src="https://i2.wp.com/peter.solymos.org/images/2018/08/30/MmPlot.png?w=456" data-recalc-dims="1"></p>
<h2>Let the best model win</h2>
<p>So which of the 3 parametrizations proved to be best for our Ovenbird example data? It was the finite mixture with time-varying proportion of infrequent singers with a thin margin. Second was the other finite mixture model, while the conventional model was lagging behind.</p>
<div>
<div>
<pre><code><span>M_AIC</span><span> </span><span>&lt;-</span><span> </span><span>AIC</span><span>(</span><span>MeBest</span><span>,</span><span> </span><span>MfBest</span><span>,</span><span> </span><span>MmBest</span><span>)</span><span>
</span><span>M_AIC</span><span>$</span><span>dAIC</span><span> </span><span>&lt;-</span><span> </span><span>M_AIC</span><span>$</span><span>AIC</span><span> </span><span>-</span><span> </span><span>min</span><span>(</span><span>M_AIC</span><span>$</span><span>AIC</span><span>)</span><span>
</span><span>M_AIC</span><span>
</span><span>## df AIC dAIC</span><span>
</span><span>## MeBest 2 545.4082 26.38106209</span><span>
</span><span>## MfBest 3 519.1168 0.08960974</span><span>
</span><span>## MmBest 3 519.0272 0.00000000</span><span>
</span></code></pre>
</div>
</div>
<h2>Conclusions and applications</h2>
<p>Finite mixture models provide some really nice insight into how singing behavior changes over time and, due to more parameters, they provide a better fit and thus minimize bias in population size estimates. But all this improvement comes with a price: sample size requirements (or more precisely, the number of detections required) are really high. To have all the benefits with reduced variance, one needs about 1000 non-zero observations to fit finite mixture models, 20 times more than needed to reliably fit conventional removal models. This is much higher than previously suggested minimum sample sizes.</p>
<p>Our findings also indicate that lengthening the count duration from 3 minutes to 5 - 10 minutes is an important consideration when designing field surveys to increase the accuracy and precision of population estimates. Well-informed survey design combined with various forms of removal sampling are useful in accounting for availability bias in point counts, thereby improving population estimates, and allowing for better integration of disparate studies at larger spatial scales.</p>
<p>To this end, we provide our removal model estimates as part of the <a rel="nofollow" href="https://github.com/psolymos/qpad" target="_blank"><strong>QPAD</strong></a> R package and the R functions required to fit all the above outlined removal models as part of the <a rel="nofollow" href="https://cran.r-project.org/package=detect" target="_blank"><strong>detect</strong></a> R package. We at the <a rel="nofollow" href="http://www.borealbirds.ca/" target="_blank">Boreal Avian Modelling Project</a> and our collaborators are already utilizing the removal model estimates to correct for availability bias in our continental and regional projects to inform better management and conservation of bird populations. Read more about these projects in our <a rel="nofollow" href="http://www.borealbirds.ca/library/index.php/technical_reports" target="_blank">reports</a>.</p>
<p>Please report any issues <a rel="nofollow" href="https://github.com/psolymos/detect/issues" target="_blank">here</a> and feel free to comment below!</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://peter.solymos.org/code/2018/08/30/fitting-removal-models-with-the-detect-r-package.html"> Peter Solymos - R related posts</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/X_dlAwHsZhM" height="1"></a></div>