An alternative analysis workflow

Chapter 7 Analysis using R

Previous chapters have described analysis of distance sampling data using the Distance software. Much of the code that underlies the graphical interface of the Distance software is written in the programming language R. Some people use the R software for data management and exploratory data analysis. Use of R has been made easier with the advent of a development environment R-Studio. Both pieces of software are free of charge and can be easily downloaded and installed. Please install both of those pieces of software as well as the package Distance before beginning these exercises. There are demonstrations of the process of installing R, R-Studio and R packages on the web. One such description can be found here.

Expectations before you begin this chapter

You have R, R-Studio and the Distance package installed on your computer. You have sufficient knowledge of R to

  • read a file containing data,
    • exercises here use the function read.csv(). If your data uses the comma , to separate decimals, then you will likely use read.csv2() for reading your data into R
  • how to call functions and
  • examine elements inside objects using the $ operator

This chapter guides you through analyses of data sets you have already seen in earlier sections of this workshop. Specifically, you will re-visit the

You will also analyse data from a lure survey of Scottish crossbills. Data from this type of survey, described in the lecture on multipliers (Slide 21), cannot be analysed in Distance for Windows; and demonstrates the flexibility available for distance sampling analysis using R.

The last of the files associated with each exercise is a markdown file. These files were used to create the exercises and their solutions. markdown files contain both text as well as R code. When markdown files are compiled, the code is executed and the results are inserted into the resulting document. At St Andrews, we often use markdown files as a way to combine our analysis and interpretation of distance sampling data in a single document. More information about Rmarkdown documents and their use with R-Studio can be found here.

Lecture on using R for distance sampling analysis


Conventional distance sampling - Monte Verde duck nest line transects

Fitting detection function with covariates - Hawaiian amakihi point transects

Lure point transects: dual surveys - Scottish crossbills

Multi-species survey - Montrave line transects

Lecture - overview of distance sampling analysis with R


Exercise 1 - conventional distance sampling


Solution to Exercise 1 - conventional distance sampling


Exercise 2 - covariates in detection function


Solution to Exercise 2 - covariates in detection function


Exercise 3 - lure point transects


Solution to Exercise 3 - lure point transects


Exercise 4 - analysis of multi-species surveys


Solution to Exercise 4 - analysis of multi-species surveys


Dialogue & Discussion