Practical exercises & solutions

Here you can find the exercises and solutions for the practical sessions during the course. All content is here and will remain here on the Distance website for future consultation.

R packages

To ensure that the below practicals and their solutions run on your computer, ensure that the following R packages1 are installed:

install.packages(c("Distance", "dsm", "ggplot2", "knitr", "plyr",
                   "raster", "reshape2", "rgdal", "viridis",
                   "htmltools", "caTools", "bitops", "rmarkdown",
                   "tweedie"))

Practicals

Practicals are provided in both RMarkdown (.Rmd) and HTML format. RMarkdown can be opened in RStudio and the file “knitted” into the corresponding HTML.

Note that the practicals are designed to be run sequentially, files generated from previous analyses are loaded and used in subsequent analyses.

Solutions

If you wish to run the solution .Rmd files on your own machine, then please use the data from day 4, as there is some extra content that requires all of the data in order to work. Additionally, you will need this CSS file to colour-code the solutions (just put it in the same directory as your .Rmd files).

Practicals, data and solutions

Practical Description Exercise Solutions Data
Fit detection functions Rmd HTML Rmd HTML zipped gdb
Process data from ArcGIS in R Rmd HTML(1)2 HTML(2) (none) Use as below3
Fitting simple DSMs Rmd HTML Rmd HTML zipped gdb
Advanced DSMs Rmd HTML Rmd HTML zipped gdb
Predictions Rmd HTML Rmd HTML zipped gdb
Variance estimation Rmd HTML Rmd HTML zipped gdb

If you run into a problem running any of these examples, please report an issue on this GitHub repository.

1 You can get the latest versions of the distance sampling related R packages by installing them from GitHub. See instructions here. 2 You’ll need to run the process-geodata.Rmd file before “Fitting simple DSMs” and again before “Advanced DSMs” to ensure that you have the updated covariates from the GIS. After “Advanced DSMs” the sperm-whale.RData file can be used for subsequent analyses. 3 process-geodata.Rmd is run either using data from “Fitting simple DSMs” or “Advanced DSMs”.