-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariance.html
More file actions
420 lines (387 loc) · 20.3 KB
/
variance.html
File metadata and controls
420 lines (387 loc) · 20.3 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="E Rexstad" />
<meta name="date" content="2020-01-23" />
<title>Variance estimation</title>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css" data-origin="pandoc">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(title);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
for (var j = 0; j < rules.length; j++) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') continue;
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<style type="text/css">body {
background-color: #fff;
margin: 1em auto;
max-width: 700px;
overflow: visible;
padding-left: 2em;
padding-right: 2em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.35;
}
#TOC {
clear: both;
margin: 0 0 10px 10px;
padding: 4px;
width: 400px;
border: 1px solid #CCCCCC;
border-radius: 5px;
background-color: #f6f6f6;
font-size: 13px;
line-height: 1.3;
}
#TOC .toctitle {
font-weight: bold;
font-size: 15px;
margin-left: 5px;
}
#TOC ul {
padding-left: 40px;
margin-left: -1.5em;
margin-top: 5px;
margin-bottom: 5px;
}
#TOC ul ul {
margin-left: -2em;
}
#TOC li {
line-height: 16px;
}
table {
margin: 1em auto;
border-width: 1px;
border-color: #DDDDDD;
border-style: outset;
border-collapse: collapse;
}
table th {
border-width: 2px;
padding: 5px;
border-style: inset;
}
table td {
border-width: 1px;
border-style: inset;
line-height: 18px;
padding: 5px 5px;
}
table, table th, table td {
border-left-style: none;
border-right-style: none;
}
table thead, table tr.even {
background-color: #f7f7f7;
}
p {
margin: 0.5em 0;
}
blockquote {
background-color: #f6f6f6;
padding: 0.25em 0.75em;
}
hr {
border-style: solid;
border: none;
border-top: 1px solid #777;
margin: 28px 0;
}
dl {
margin-left: 0;
}
dl dd {
margin-bottom: 13px;
margin-left: 13px;
}
dl dt {
font-weight: bold;
}
ul {
margin-top: 0;
}
ul li {
list-style: circle outside;
}
ul ul {
margin-bottom: 0;
}
pre, code {
background-color: #f7f7f7;
border-radius: 3px;
color: #333;
white-space: pre-wrap;
}
pre {
border-radius: 3px;
margin: 5px 0px 10px 0px;
padding: 10px;
}
pre:not([class]) {
background-color: #f7f7f7;
}
code {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-size: 85%;
}
p > code, li > code {
padding: 2px 0px;
}
div.figure {
text-align: center;
}
img {
background-color: #FFFFFF;
padding: 2px;
border: 1px solid #DDDDDD;
border-radius: 3px;
border: 1px solid #CCCCCC;
margin: 0 5px;
}
h1 {
margin-top: 0;
font-size: 35px;
line-height: 40px;
}
h2 {
border-bottom: 4px solid #f7f7f7;
padding-top: 10px;
padding-bottom: 2px;
font-size: 145%;
}
h3 {
border-bottom: 2px solid #f7f7f7;
padding-top: 10px;
font-size: 120%;
}
h4 {
border-bottom: 1px solid #f7f7f7;
margin-left: 8px;
font-size: 105%;
}
h5, h6 {
border-bottom: 1px solid #ccc;
font-size: 105%;
}
a {
color: #0033dd;
text-decoration: none;
}
a:hover {
color: #6666ff; }
a:visited {
color: #800080; }
a:visited:hover {
color: #BB00BB; }
a[href^="http:"] {
text-decoration: underline; }
a[href^="https:"] {
text-decoration: underline; }
code > span.kw { color: #555; font-weight: bold; }
code > span.dt { color: #902000; }
code > span.dv { color: #40a070; }
code > span.bn { color: #d14; }
code > span.fl { color: #d14; }
code > span.ch { color: #d14; }
code > span.st { color: #d14; }
code > span.co { color: #888888; font-style: italic; }
code > span.ot { color: #007020; }
code > span.al { color: #ff0000; font-weight: bold; }
code > span.fu { color: #900; font-weight: bold; }
code > span.er { color: #a61717; background-color: #e3d2d2; }
</style>
</head>
<body>
<h1 class="title toc-ignore">Variance estimation</h1>
<h4 class="author">E Rexstad</h4>
<h4 class="date">23 January 2020</h4>
<p>Continuing with the Montrave winter wren line transect data from the line transect vignette, we focus upon producing robust estimates of precision in our point estimates of abundance and density. The analysis in <code>R</code> <span class="citation">(R Core Team, 2019)</span> makes use of the <code>Distance</code> package <span class="citation">(Miller, Rexstad, Thomas, Marshall, & Laake, 2019)</span>.</p>
<div id="objectives" class="section level1">
<h1>Objectives</h1>
<ul>
<li>Estimate precision in the standard manner</li>
<li>Use the bootstrap to estimate precision</li>
<li>Incorporate model uncertainty in our estimates of precisio</li>
</ul>
</div>
<div id="survey-data" class="section level1">
<h1>Survey data</h1>
<p>The R workspace <code>wren_lt</code> contains detections of winter wrens from the line transect surveys of Buckland <span class="citation">(2006)</span>.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">library</span>(Distance)</a>
<a class="sourceLine" id="cb1-2" title="2"><span class="kw">data</span>(wren_lt)</a></code></pre></div>
<p>The function <code>names()</code> allows you to see the names of the columns of the data frame <code>wren_lt</code>. Definitions of those fields were provided in the <a href="https://examples.distancesampling.org/Distance-lines/linetransects.html">line transect vignette</a>.</p>
<p>The effort, or transect length has been adjusted to recognise each transect is walked twice.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" title="1">conversion.factor <-<span class="st"> </span><span class="kw">convert_units</span>(<span class="st">"meter"</span>, <span class="st">"kilometer"</span>, <span class="st">"hectare"</span>)</a></code></pre></div>
</div>
<div id="fitting-a-suitable-detection-function" class="section level1">
<h1>Fitting a suitable detection function</h1>
<p>Rather than refitting models used in the line transect vignette, we move directly to the model selected by Buckland <span class="citation">(2006)</span>.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">wren.unif.cos <-<span class="st"> </span><span class="kw">ds</span>(wren_lt, <span class="dt">key=</span><span class="st">"unif"</span>, <span class="dt">adjustment=</span><span class="st">"cos"</span>,</a>
<a class="sourceLine" id="cb3-2" title="2"> <span class="dt">convert.units=</span>conversion.factor)</a></code></pre></div>
<p>Based upon experience in the field, the uniform cosine model was used for inference.</p>
</div>
<div id="estimation-of-precision" class="section level1">
<h1>Estimation of precision</h1>
<p>Looking at the density estimates from the uniform cosine model</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1"><span class="kw">print</span>(wren.unif.cos<span class="op">$</span>dht<span class="op">$</span>individuals<span class="op">$</span>D)</a></code></pre></div>
<pre><code>## Label Estimate se cv lcl ucl df
## 1 Total 1.067167 0.2125562 0.1991781 0.7229706 1.57523 168.1381</code></pre>
<p>The coefficient of variation (CV) is 0.199, and confidence interval bounds are (0.72 - 1.58) birds per hectare. The coefficient of variation is based upon a delta-method approximation of the uncertainty in both the parameters of the detection function and the variability in encounter rates between transects.</p>
<p><span class="math display">\[[CV(\hat{D})]^2 = [CV(\frac{n}{L})]^2 + [CV(P_a)]^2\]</span> where</p>
<ul>
<li><span class="math inline">\(n\)</span> is number of detections</li>
<li><span class="math inline">\(L\)</span> is total effort</li>
<li><span class="math inline">\(P_a\)</span> is probability of detection given a bird is within the covered region.</li>
</ul>
<p>These confidence interval bounds assume the sampling distribution of <span class="math inline">\(\hat{D}\)</span> is log-normal <span class="citation">(Buckland, Rexstad, Marques, & Oedekoven, 2015, Section 6.2.1)</span>.</p>
<div id="bootstrap-estimates-of-precision" class="section level2">
<h2>Bootstrap estimates of precision</h2>
<p>Rather than relying upon the delta-method approximation that assumes independence between uncertainty in the detection function and variability in encounter rate, a bootstrap procedure can be employed. Resampling with replacement of the transects produces replicate samples with which a sampling distribution of <span class="math inline">\(\hat{D}\)</span> is approximated. From that sampling distribution, the percentile method is used to produce confidence interval bounds respecting the shape of the sampling distribution <span class="citation">(Buckland et al., 2015, Section 6.3.1.2)</span>.</p>
<p>The function <code>DNhat_summarize_indiv</code> is included in the <code>Distance</code> package. It is used to extract information from the object created by <code>bootdht</code>.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" title="1">DNhat_summarize_indiv <-<span class="st"> </span><span class="cf">function</span>(ests, fit) {</a>
<a class="sourceLine" id="cb6-2" title="2"> <span class="kw">return</span>(<span class="kw">data.frame</span>(<span class="dt">D=</span>ests<span class="op">$</span>individuals<span class="op">$</span>D<span class="op">$</span>Estimate,</a>
<a class="sourceLine" id="cb6-3" title="3"> <span class="dt">N=</span>ests<span class="op">$</span>individuals<span class="op">$</span>N<span class="op">$</span>Estimate))</a>
<a class="sourceLine" id="cb6-4" title="4">}</a></code></pre></div>
<p>After the summary function is defined, the bootstrap procedure can be performed. Arguments here are the name of the fitted object, the object containing the data, conversion factor and number of bootstrap replicates.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" title="1">est.boot <-<span class="st"> </span><span class="kw">bootdht</span>(<span class="dt">model=</span>wren.unif.cos, <span class="dt">flatfile=</span>wren_lt,</a>
<a class="sourceLine" id="cb7-2" title="2"> <span class="dt">summary_fun=</span>DNhat_summarize_indiv,</a>
<a class="sourceLine" id="cb7-3" title="3"> <span class="dt">convert.units=</span>conversion.factor, <span class="dt">nboot=</span><span class="dv">99</span>)</a></code></pre></div>
<p>The object <code>est.boot</code> contains a data frame with two columns consisting of <span class="math inline">\(\hat{D}\)</span> and <span class="math inline">\(\hat{N}\)</span> as specified in <code>DNhat_summarize_indiv</code>. This data frame can be processed to produce a histogram representing the sampling distribution of the estimated parameters as well as the percentile confidence interval bounds.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" title="1">alpha <-<span class="st"> </span><span class="fl">0.05</span></a>
<a class="sourceLine" id="cb8-2" title="2">(bootci <-<span class="st"> </span><span class="kw">quantile</span>(est.boot<span class="op">$</span>D, <span class="dt">probs =</span> <span class="kw">c</span>(alpha<span class="op">/</span><span class="dv">2</span>, <span class="dv">1</span><span class="op">-</span>alpha<span class="op">/</span><span class="dv">2</span>)))</a></code></pre></div>
<pre><code>## 2.5% 97.5%
## 0.905190 1.399154</code></pre>
</div>
</div>
<div id="incorporating-model-uncertainty-in-precision-estimates" class="section level1">
<h1>Incorporating model uncertainty in precision estimates</h1>
<p>The argument <code>model</code> in <code>bootdht</code> can be a single model as shown above, or it can consist of a list of models. In the later instance, all models in the list are fitted to each bootstrap replicate and model selection based on AIC is performed for each replicate. The consequence is that model uncertainty is incorporated into the resulting estimate of precision.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" title="1">wren.hn <-<span class="st"> </span><span class="kw">ds</span>(wren_lt, <span class="dt">key=</span><span class="st">"hn"</span>, <span class="dt">adjustment=</span><span class="ot">NULL</span>,</a>
<a class="sourceLine" id="cb10-2" title="2"> <span class="dt">convert.units=</span>conversion.factor)</a>
<a class="sourceLine" id="cb10-3" title="3">wren.hr.poly <-<span class="st"> </span><span class="kw">ds</span>(wren_lt, <span class="dt">key=</span><span class="st">"hr"</span>, <span class="dt">adjustment=</span><span class="st">"poly"</span>,</a>
<a class="sourceLine" id="cb10-4" title="4"> <span class="dt">convert.units=</span>conversion.factor)</a>
<a class="sourceLine" id="cb10-5" title="5">est.boot.uncert <-<span class="st"> </span><span class="kw">bootdht</span>(<span class="dt">model=</span><span class="kw">list</span>(wren.hn, wren.hr.poly, wren.unif.cos), </a>
<a class="sourceLine" id="cb10-6" title="6"> <span class="dt">flatfile=</span>wren_lt,</a>
<a class="sourceLine" id="cb10-7" title="7"> <span class="dt">summary_fun=</span>DNhat_summarize_indiv,</a>
<a class="sourceLine" id="cb10-8" title="8"> <span class="dt">convert.units=</span>conversion.factor, <span class="dt">nboot=</span><span class="dv">99</span>)</a></code></pre></div>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb11-1" title="1">(modselci <-<span class="st"> </span><span class="kw">quantile</span>(est.boot.uncert<span class="op">$</span>D, <span class="dt">probs =</span> <span class="kw">c</span>(alpha<span class="op">/</span><span class="dv">2</span>, <span class="dv">1</span><span class="op">-</span>alpha<span class="op">/</span><span class="dv">2</span>)))</a></code></pre></div>
<pre><code>## 2.5% 97.5%
## 0.8585906 1.3763014</code></pre>
</div>
<div id="comments" class="section level1">
<h1>Comments</h1>
<p>Recognise that producing bootstrap estimates of precision is computer-intensive. In this example we have created only 99 bootstrap replicates in the interest of computation time. For inference you wish to draw, you will likely increase the number of bootstrap replicates to 999.</p>
<p>For this data set, the bootstrap estimate of precision is greater than the delta-method approximation precision (based on confidence interval width). In addition, incoroprating model uncertainty into the estimate of precision for density changes the precision estimate very little. The confidence interval width without incorporating model uncertainty is 0.494 while the confidence interval with including model uncertainty is 0.518. This represents an increase of 5% due to uncertainty regarding the best model for these data.</p>
</div>
<div id="references" class="section level1 unnumbered">
<h1>References</h1>
<div id="refs" class="references">
<div id="ref-buckland2015distance">
<p>Buckland, S., Rexstad, E., Marques, T., & Oedekoven, C. (2015). <em>Distance sampling: Methods and applications</em>. Springer.</p>
</div>
<div id="ref-Buckland2006">
<p>Buckland, S. T. (2006). Point transect surveys for songbirds: Robust methodologies. <em>The Auk</em>, <em>123</em>(2), 345–345. <a href="https://doi.org/10.1642/0004-8038(2006)123%5B345:psfsrm%5D2.0.co;2">https://doi.org/10.1642/0004-8038(2006)123[345:psfsrm]2.0.co;2</a></p>
</div>
<div id="ref-miller_distance_2019">
<p>Miller, D. L., Rexstad, E., Thomas, L., Marshall, L., & Laake, J. L. (2019). Distance Sampling in R. <em>Journal of Statistical Software</em>, <em>89</em>(1), 1–28. <a href="https://doi.org/10.18637/jss.v089.i01">https://doi.org/10.18637/jss.v089.i01</a></p>
</div>
<div id="ref-r_core_team_r_2019">
<p>R Core Team. (2019). <em>R: A Language and Environment for Statistical Computing</em>. Vienna Austria: R Foundation for Statistical Computing.</p>
</div>
</div>
</div>
<!-- code folding -->
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>