Estimating Population Size: Grasshopper Lab

2006-09-29 16:00

Objective

In this lab, you will learn how to write a function in R to calculate an unbiased estimate of grasshopper population size using the formulas given in the lab manual.

Writing Functions in R

Recall that R can be used as a simple calculator. For example, to add 2 and 3 together:

2+3

This works fine, except that you may want to evaluate more complicated algebraic expressions, such as x^2+y^2+z^2-2*x-y+3*z+1. Moreover, you may want to do this for several values of x, y, and z.

One way to approach this is to assign values of x, y, and z prior to evaluating the expression:

x <- 2
y <- 3
z <- 1
x^2+y^2+z^2-2*x-y+3*z+1

You can then change the values of x, y, and z as needed.

An even better way to do this is to make the expression into a function. In R, this can be done by using the function function(). One example of a simple function is:

simple.fn <- function(x) x^2 # Here we create a function for the variable x
simple.fn(2) # Here we evaluate the function for x=2

If you want a function with two or more variables, just separate them with a comma. For example, the "complicated" equation above can be written:

test.fn <- function(x,y,z) x^2+y^2+z^2-2*x-y+3*z+1
test.fn(2,3,4)

Similarly, consider the expression for evaluating the standard deviation of the population size estimate from your lab manual (equation 5). This can be written as a function in R as follows:

stdev.fn <- function(s,r,M) sqrt( (M*r^2*(s+1)*(s-r)) / ((r+1)*r^2*(r+2)) )

Finally, note that you can write functions for all sorts of things in R. Below is a function I've written to graph the results of you analyses. Note the use of brackets { ... } which is used because the function is written over more than one line.

grasshopper.plot <- function(mean, std, ...) {
CI.H <- mean+1.96*std # Calculate upper CI
CI.L <- mean-1.96*std # Calculate lower CI
xvals <- barplot(mean, ylim=c(0, max(CI.H)), ...) # Plot bars
arrows(xvals, mean, xvals, CI.H, angle=90) # Draw error bars
arrows(xvals, mean, xvals, CI.L, angle=90)
}

Try the example "grasshopper plot" below with fancy green color and with colum labels assigned using the option names.arg:

ex.means <- c(1,2,3) # Vector of made-up population estimates
ex.stds <- c(.5,.2,.3) # Vector of made-up standard deviations
grasshopper.plot(ex.means, ex.stds, col="green", names.arg=c("A","B","C"))

Data

The table below gives the mark and recapture numbers for the species we recorded. The numbers in parentheses indicate the number of marked individuals recaptured with "T" indicating recaptures from Tuesday's mark and "W" indicating recaptures from Wednesday's mark.

Mark/Recapture Period Spur-Thorated Long-Horned Slant-Faced Pygmies et al. Totals
Tuesday Mark 8 3 1 0 12
Wednesday Mark 6 (3T) 1 7 3 17
Wednesday Recapture 8 (1W) 3 1 0 15



The table below gives the movement rates between the inside and outside circles:

  Recaptured Inside Recaptured Outside
Marked Inside

0 0
Marked Outside

2 2



Finally, in 2003, the Ecology class did a mark/recapture lab in the same field as you did. They caught a total of 71 grasshoppers in the initial mark and 135 grasshoppers during the recapture period, of which 43 had been marked.

Worksheet Questions

  1. Write a function in R for estimating population size from mark-recapture data using equation 3 in your lab manual. Note that your function will be based on the rhs (right-hand side) of Eq. 3 - don't try to include N as a "variable" - "N" is what your function should return. Make sure to include your code when you hand in your worksheet.
  2. Use your function and the function stdev.fn() above to estimate population size and to calculate the standard deviation of this estimate for all grasshoppers (species combined) using the following data:
    • Tuesday's mark and Wednesday's recapture data (Note that there is some ambiguity here - make sure to identify what data you are using for the Wednesday recapture period).
    • Tuesday and Wednesday's mark (combined as the mark period) and and Wednesday's recapture data.
    • Mark/Recapture data from the 2003 Ecology class
  3. Use the function grasshopper.plot() to compare the 95% confidence intervals of your three estimates and to determine if there is a significant difference between them. If neither interval overlaps the other's mean, consider the estimates to be significantly different (see discussion in Chapter 1 of your text).
    • Is there any significant difference between the estimates of total grasshopper abundance between years or recapture periods?
    • Give at least two possible explanations to account for your previous answer.
    • Regardless of your empirical results, develop a hypothesis and propose an experiment to explain differences in grasshopper abundance between years.
  4. How would emigration or immigration affect your estimate of population size. You may find it easiest to answer this question by changing the values for s, r, or M concordant with changes in emigration or immigration.