knitr::opts_chunk$set(echo = TRUE, warning=FALSE, comment='#>', 
                      message=FALSE, eval=TRUE,
                      collapse=TRUE, dev='png')

(Very) Brief Introduction to Distance Sampling using the mrds library

# load workpace
require(ggplot2)
require(RColorBrewer)
require(splines)
require(fields)
  1. Load data and fit detection function (Distance Sampling)

This first step uses the mrds R package to fit a detection function model. More information on using this package can be found in its help files and also the Distance Sampling web pages

Here we fit a simple half normal detection function with no covariates and one with season as a covariate that may affect detectability of the animals.

library(mrds)
# we will use the dataset with a known re-distribution of animals
data(dis.data.re, package = "MRSea")
dis.data<-dis.data.re

For the MRSea functions that we will use to generate the adjusted counts per segment it is best that the data for analysis are already segmented and including all the zero segments. Each row is either a zero segment (with object and distance set to NA) or a detection with a segment label (there may be more than one detection per segment). The columns in our data are as follows:

Additional observation level covariates may be present such as glare, sea state or observer

head(dis.data)

The detection data has information in the object and distance columns relating to the sightings.

library(dplyr)
filter(dis.data, !is.na(distance)) %>% head

Simple detection function model with no covariates

result <- ddf(dsmodel=~mcds(key="hn", formula=~1),
              data = dis.data, method="ds", 
              meta.data=list(width=250))
summary(result)

Detection function model with one covariate, season.

result.season <- ddf(dsmodel=~mcds(key="hn", formula=~season),
              data = dis.data, method="ds", 
              meta.data=list(width=250))
summary(result.season)
par(mfrow=c(2,2))
plot(result.season, subset = season==1)
plot(result.season, subset = season==2)
plot(result.season, subset = season==3)
plot(result.season, subset = season==4)
BIC(result)
BIC(result.season)

First the adjusted counts for each detection are estimated using the create.NHAT function from the MRSea package. The adjustment is the number of observed individuals divided by their probability of detection. Additionally, the area (in km) column is also created using the segment length and truncation distance.

library(MRSea)
dis.data <- create.NHAT(dis.data,result)

Then the create.count.data function is used to collapse the data down into one row per segment. The estimated counts are summed within each segment and the distance related variables removed (distance, size, object).

If availability information is present, then these adjustments may also be made here.

count.data <- create.count.data(dis.data)

These count data are now ready for analysis using the main MRSea functions. Specifically, spatially adaptive smoothing in one and two dimensions.



lindesaysh/MRSea documentation built on May 11, 2024, 11:30 p.m.