In this lab, we will continue learning how to use R to create and manipulate objects, with a particular focus on estimating abundance using the Lincoln-Peterson estimator.


Objectives

  • Learn/review basic data types, including:
    • Scalars
    • Vectors
    • Numeric objects
    • Character objects
  • Learn/review basic data manipulation tasks, including:
    • Vector algebra
  • R functions used in this exercise:

Set up

  1. Log in to R Studio Cloud

  2. Create a new project called LastnameFirstname-Lab1

  3. Create a new R script file to store code from this lab:

    3a) Click File -> New File -> R Script

    3b) Save the script as Lab1

The Lincoln-Peterson estimator

Remember from lecture 2 that the Lincoln-Peterson method is used to estimate the abundance of a closed population using mark-recapture data. As a reminder, the Lincoln-Peterson estimator is:

\[N = \frac{n_1n_2}{m_2}\]

where \(n_1\) is the number of individuals captured (and marked) on the first sampling occasion, \(n_2\) is the number of individuals captured on the second sampling occasion, and \(m_2\) is the number of marked individuals in the second sample.

Let’s use Rto estimate N for some made up data. In the script you just opened, create three new objects that represent the parameters in the Lincoln-Peterson estimator. Modify the following code to tell Rthat we captured 44 individuals on the first occasion, 32 on the second, and of those 32 sampled on the second occasion, 15 were marked:

Remember that R will ignore any code that follows a #. Before moving on, use comments to define what each object represents (e.g., Number of individuals captured on first occasion, Number of individuals captured on second occasion, Number of previously marked individuals captured on second occasion)

After entering the code and comments, highlight all three lines and then click Ctrl + Enter (or command + return on Mac) to run the code. Note that you should see the code in the console.

Now add a new line of code (put your cursor at the end of the m2 <- line and hit enter) and estimate \(N\) from our newly created objects using the Lincoln-Peterson:

N <- n1 * n2 / m2

What is the estimated abundance of this population?

Remember that, in addition to our estimate of N, we always need to know something about how certain we are in the estimate. On your own, create a new object called varN to calculate the variance of our estimated N, remembering that:

\[\large var(\hat{N}) = \frac{(n_1 + 1)(n_2+1)(n_1-m_2)(n_2-m_2)}{(m_2+1)^2(m_2+2)}\]

Hints: Remember that the entire numerator (and denominator) needs to be contained within parentheses; to square something in R, use ^2

Exercise 2: The Schnabel method

To better understand how we use vectors in R and to expand on our discussion of abundance estimation, we will learn how to use the Schnabel method to estimate \(N\).

In many studies, researchers attempt to re-sight marked individuals on more than 2 occasions. Unfortunately, the Lincoln-Peterson method is restricted to data from only 2 capture occasions, meaning that to use it, we have to throw out data from occasions \(3,4,...,T\).

In the 1930’s, a mathematician at the University of Wisconsin named Zoe Emily Schnabel, expanded on the Lincoln-Peterson method to include \(>2\) occasions. The Schnabel method uses three pieces of information collected at each occasion: \(C_t\), the number of captured individuals during occasion \(t\); \(R_t\), the number of recaptures captured during occasion \(t\); and \(M_t\), the number of individuals marked in the population at occasion \(t\) (or, the total number of marked individuals at risk of being captured on occasion \(t\)). Using these data, the Schnabel estimator is:

\[\hat{N} = \frac{\sum_t(C_t \times M_t)}{\sum_t R_t}\] Remember that \(\sum_t\) means the sum of the values across at \(T\) occasions.

To better understand what each of these data mean, we will use an example from Powell & Gale (2015) (pages 96-97). Students on a research trip to Puerto Rico did a 3-day mark-recapture study to estimate the number of Cuban rock iguanas (Cyclura nubila) on the island Isla Magueyes. On the first day, the students observed and marked (using latex paint) 155 iguanas. On the second day, they observed 175 individuals (109 marked and 66 unmarked; note that the 66 unmarked individuals were captured, marked, and released). On the third day, they observed 131 individuals (116 marked and 15 unmarked).

Day Animals Observed Animal with marks
1 155 0
2 175 109
3 131 116

In this example, \(C_t =\)

Ct <- c(155, 175, 131) # Number of captures during each occassion

and \(R_t =\)

Rt <- c(0, 109, 116) # Number of recaptures during each occassion

What is \(M_t\)? On the first day, there are no previously marked individuals so \(M_1=0\). On the second day, there are 155 marked individuals in the population (all of the individuals marked on day 1) so \(M_2=155\). On day 3, the students could have observed individuals marked on the first day or individuals marked on the second day (\(175-109=66\) individuals marked on day 2) so \(M_3 = 155 + 66 = 221\). So:

Mt <- c(0, 155, 221) # Number of recaptures during each occassion

Now to estimate \(\hat{N}\). We could do it by hand:


N <- ((155*0) + (175 * 155) + (131 * 221)) / (0 + 109 + 116)

However, that is a lot of typing and it’s pretty likely we would make a mistake somewhere along the way (typos or misplaced parentheses). R is clever enough to allow us to use the previously created vectors. First, let’s see what happens when we multiply two vectors together:

Ct * Mt
#> [1]     0 27125 28951

As you can see, we created a new vector that is the same length as the original vectors (3). When you multiply (or add, subtract, or divide) two vectors, R multiplies the first element of first vector times the first element of the second vector, the second element of first vector times the second element of the second vector, the third element of first vector times the third element of the second vector, etc, and then combines them into a new vector.

We can also use the sum() function to add up all of the elements of a vector (similar to the prod() function we saw earlier). So:

N <- sum(Ct * Mt) / sum(Rt)
round(x = N, digits = 0)
#> [1] 249

Much easier!

Properties of the Lincoln-Peterson estimator

In the next homework, we will use R to better understand the properties of the LP estimator. To create this homework:

  1. Create a new R Markdown file from the Homework-1 template:

    1a) Click File -> New File -> R Markdown

    1b) Click From Template and scroll down to WILD3810-Homework1

    1c) In the Name box, type LastnameFirstname-Homework1

    1d) Click Ok

  2. Ensure that you can Knit the file

    2a) Change “YOUR NAME HERE” in the header section to your name

    2b) Click Knit to make sure you can knit the .Rmd file

  3. Complete the assignment as directed in the .Rmd file

  4. Follow the instructions for submission to upload your completed assignment to Canvas