-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrac_3_Assessing_LT_detection_functions.Rmd
185 lines (134 loc) · 8.38 KB
/
Prac_3_Assessing_LT_detection_functions.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
title: Exercise 3<br> Assessing line transect detection functions
author: Centre for Research into Ecological and Environmental Modelling <br> **University of St Andrews**
date: Introduction to distance sampling<br> August/September 2022
output:
rmdformats::readthedown:
highlight: tango
bibliography: references.bib
csl: apa.csl
---
```{r setup, include=FALSE, message=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
answer <- FALSE
```
In Exercise 2, we fitted different detection functions and compared them in terms of goodness of fit and AIC. Here, we continue to fit and assess different models and look at additional arguments in the `ds` package.
# Objectives
The aim of this exercise is to practise fitting and assessing different line transect detection functions and in particular to:
1. Understand the data format when there are no detections on a line,
2. Explore different truncation options,
3. Determine whether adjustment terms are required,
4. Practice model selection,
# Fitting models to simulated data
The data used for this practical were generated from a half-normal distribution and therefore the true density is known. There are 12 transects.
The data are stored in a data set `LTExercise3` which contains the following columns:
- Study.Area - Name of study called (not very imaginatively) 'LTExercise3'
- Region.Label - identifier of regions (in this case there is only one region and it is set to 'Default')
- Area - size of the study region (km$^2$)
- Sample.Label - line transect identifier (Line 1 - Line 12)
- Effort - length of the line transects (km)
- object - unique identifier to each detected object
- distance - perpendicular distances (metres).
## Accessing the data
Load the `Distance` package to access both the data and analytical functions.
```{r, echo=TRUE, eval=FALSE}
# Load library (if not already loaded)
library(Distance)
# Access data
data("LTExercise")
# Check that it has been imported correctly
head(LTExercise, n=3)
```
### Data format: no detections on a transect
Before fitting models, it is worth investigating the data a bit further: let's start by summarising the perpendicular distances:
```{r, echo=TRUE, eval=FALSE}
# Summary of perpendicular distances
summary(LTExercise$distance)
```
The summary indicates that the minimum distance is `min(hndat$distance)` and the maximum is `max(hndat$distance)` metres and there is one missing value (indicated by the `NA`). If we print a few rows of the data, we can see that this missing value occurred on transect 'Line 11'.
```{r, echo=TRUE, eval=FALSE}
# Print out a few lines of data
LTExercise[100:102, ]
```
The `NA` indicates that there were no detections on this transect, but the transect information needs to be included otherwise the number of transects and the total line length will be incorrect.
## Truncation
Let's start by fitting a basic model, i.e. no adjustment terms (by default a half normal model is fitted).
For this project, perpendicular distances are in metres and the transect lines are recorded in kilometres.
```{r, echo=TRUE, eval=FALSE, message=FALSE}
conversion.factor <- convert_units("meter", "kilometer", "square kilometer")
# Fit half normal, no adjustments
lt.hn <- ds(data=LTExercise, key="hn", adjustment=NULL,
convert_units=conversion.factor)
```
Looking at a summary of the model object, how many objects are there in total? What is the maximum observed perpendicular distance?
```{r, echo=TRUE, eval=FALSE}
# Print a summary of the fitted detection function
summary(lt.hn)
```
Plot the detection function and specify many histogram bins:
```{r, echo=TRUE, eval=FALSE, fig.height=4, fig.width=4}
plot(lt.hn, nc=30)
```
The histogram indicates that there is a large gap in detections therefore, to avoid a long right hand tail in the detection function, truncation is necessary. There are several ways to truncate: excluding distances beyond some specified distance or excluding a specified percentage of the largest distances. Note that here we only consider excluding large perpendicular distances, which is frequently referred to as right truncation.
### Truncation at a fixed distance
The following command truncates the perpendicular distances at 20 metres i.e. objects detected beyond 20m are excluded.
```{r, echo=TRUE, eval=FALSE, message=FALSE}
# Truncate at 20metres
lt.hn.t20m <- ds(data=LTExercise, key="hn", adjustment=NULL, truncation=20,
convert_units=conversion.factor)
```
Generate a summary and plot of the detection function to see what effect this truncation has had on the number of objects.
```{r, echo=answer, eval=answer, fig.height=4, fig.width=4}
# Generate a summary
summary(lt.hn.t20m)
# Plot detection function
plot(lt.hn.t20m)
```
### Truncating a percentage of distances
An alternative way to truncate distances is to specify a percentage of detected objects that should be excluded. In the command below, 10% of the largest distances are excluded.
```{r, echo=TRUE, eval=FALSE, message=FALSE}
# Truncate largest 10% of distances
lt.hn.t10per <- ds(data=LTExercise, key="hn", adjustment=NULL, truncation="10%",
convert_units=conversion.factor)
```
Generate a summary and plot to see what effect truncation has had.
```{r, echo=TRUE, eval=FALSE, fig.height=4, fig.width=4}
summary(lt.hn.t10per)
plot(lt.hn.t10per)
```
## Exploring different models
Decide on a suitable truncation distance (but don't spend too long on this) and then fit different key detection functions and adjustment terms to assess whether these data can be satisfactorily analysed with the 'wrong' model. By default, the `ds` function fits a half normal function and cosine adjustment terms (`adjustment="cos"`) of up to order 5: AIC is used to determine how many, if any, adjustment terms are required. This model is specified in the command below:
```{r, echo=TRUE, eval=FALSE, message=FALSE}
# Half normal detection, cosine adjustments, no truncation
lt.hn.cos <- ds(data=LTExercise, key="hn", adjustment="cos",
convert_units=conversion.factor)
```
Change the key and adjustment terms: possible options are listed in Exercise 2 or use the `help(ds)` for options. See how the bias and precision compare between the models: the true density was 79.8 animals per km$^2$.
# Fitting models to real data (optional question)
- The objective of this portion of the exercise is to give you more practice with a line transect data set and also familiarise you with converting from exact distances to binned distances.
The data stored in a data set `capercaillie` were collected during a line transect survey of capercaillie (a species of large grouse) in Scotland. For a paper demonstrating a distance sampling survey of this species, consult [@catt1998a]. The data consist of:
- Region.Label - name of the region
- Area - size of region in hectares *(1 hectare = 100m* $\times$ 100m)
- Sample.Label - line transect identifier (one transect)
- Effort - length of line (km)
- object - unique identifier for each group detected
- distance - perpendicular distance to each group (metres)
- size - group size (in this case only single birds were detected)
Access these data and:
1. Decide on a suitable truncation distance, if any,
2. Fit a few different key detection functions and adjustment terms
3. Compare the AIC values and qq plots and choose a model
4. Calculate density for your chosen model. To obtain density in birds per hectare, the conversion units should be specified as `conversion.factor<-convert_units("meter", "kilometer", "hectare")`.
## Converting exact distances to binned distances
Sometimes we wish to convert exact distances to binned distances, if for example, there is evidence of rounding to favoured values. To do this in `ds` we need to specify the cutpoints of the bins, including zero and the maximum distance. In the example below, cutpoints at 0, 10, 20, ..., 80 are specified.
```{r, echo=TRUE, eval=FALSE}
data(capercaillie)
# Specify cutpoint for bins
bins <- seq(from=0, to=80, by=10)
conversion.factor <- convert_units("meter", "kilometer", "hectare")
# Fit model with binned distances
caper.bin <- ds(data=capercaillie, key="hn", cutpoints=bins,
convert_units=conversion.factor)
plot(caper.bin)
```
# References