# BIOL 521: PVA by Stochastic Leslie Matrix Projection
# Approach using matrix entries that specify a
# mean and variance (and a specific distribution)
# for each demographic variable in the matrix
# Scott Creel 11/17/2011
# INTRODUCTION
# This exercise builds a stochastic Leslie matrix to estimate extinction risk for
# African wild dogs, using the data from Tanzania's Selous Game Reserve that we used
# in class to build a life table and estimate lambda.
#
# In the previous exercise you saw the 'multiple matrices' approach to
# stochastic projection... This approach assembles a set of Leslie matrices and randomly
# draws one entire matrix for each step of projection. This approach assumes that all of the
# demographic parameters covary -- they ALL change at once.
# This assumption might not be correct, so you might want to do the projection in a manner that allows the
# demographic parameters to vary independently of one another. To do this,
# you must make random draws from a distribution for each demographic parameter,
# rather than randomly drawing whole matrices.
#
# All that this requires is:
# 1. Create a Leslie matrix in which each of the demographic parameters is specified by
# a distribution rather than a constant. You do this by specifying a distribution, a mean and a variance.
# There are other logical possibilities, but we'll use a binomial distribution for survival
# rates and a normal distribution (truncated to be non-negative) for fecundities.
# 2. Making a random draw from those distributions at each time step to get a 'stochastic Leslie matrix'.
# 3. Projecting next year's population (tracked as a vector with the number
# of individuals in each age class) with the stochastic Leslie matrix, just the same way you
# would with a simple Leslie matrix with the mean for each demographic variable.
# PART 1: BASIC DEMOGRAPHIC CALCULATIONS, SURVIVORSHIP CURVE.
# These are the African wild dog data we used to build a life table in class.
# Enter lx data (survivorship from birth) and examine survivorship curve
lx 1,rbinom(1,size=round(n),p=les.mat[(k+1),k])/n,0) # need ifelse statement to deal with the possibility
# that there are no individuals in that age class.
} # Ends the 'k' loop to draw survival rates.
stoc_year[i,]