popdemo provides tools for modelling populations and demography using matrix projection models (MPMs), with deterministic and stochastic model implementations. These tools include population projection, indices of short- and long-term population size and growth, perturbation analysis, convergence to stability or stationarity, and diagnostic and manipulation tools.

Installing popdemo

popdemo is available on CRAN as well as GitHub. The GitHub repository may be ahead of the CRAN version, so for the latest stable version check out the GitHub page. The GitHub repository also includes a development branch with a development version of the package (called popdemoDev). This is likely to be unstable but may include new features.

Vignette exercises usually require the latest version of the package (unless they’re sourced from within an older package version).

Installing from GitHub:

# Install dependencies from CRAN:
install.packages(c("devtools", "expm", "MCMCpack", "markovchain"))

# Install stable version from GitHub (recommended):
# NOTE don't forget to change the version number!
devtools::install_github("iainmstott/popdemo/x.x-x/popdemo") #x.x-x is the desired version number

# Install development version 'popdemoDev' (not recommended):
devtools::install_github("iainmstott/popdemo/Dev/popdemoDev", ref = "development")

Note that vignettes do not install automatically from GitHub. If you want vignettes to be included, include build_vignettes = TRUE.

Installing from CRAN:


Vignette layout

The two main sections Deterministic population dynamics and Stochastic population dynamics can be completed independently of one another. Within each of these two sections, core exercises are in normal print, and code in each sub-section may depend on code in previous sections. The “extras” sections (in italics), contain further exercises and tasks for independent completion: take care when working on these not to change objects from earlier core sections, as they may be needed later on. Code chunks are formatted like this:

# a comment
##   an output

Key terms in the text are in bold italic, and functions or arguments are fixed width.

Deterministic population dynamics

Desert tortoise model

We will use a matrix projection model (MPM) to explore population dynamics for the desert tortoise Gopherus agassizzii, with medium fecundity1. The population is found in the Mojave desert, USA. There are 8 stages are based on age and size (carapace length in mm):
- Yearling (age 0-1)
- Juvenile 1 (<60 mm)
- Juvenile 2 (90-99mm)
- Immature 1 (100-139mm)
- Immature 2 (140-179mm)
- Subadult (180-207mm)
- Adult 1 (208-239mm)
- Adult 2 (>240mm)

Load in the data:

data(Tort); Tort
##         Yr    J1    J2    I1    I2    SA    A1   A2
##   Yr 0.000 0.000 0.000 0.000 0.000 1.300 1.980 2.57
##   J1 0.716 0.567 0.000 0.000 0.000 0.000 0.000 0.00
##   J2 0.000 0.149 0.567 0.000 0.000 0.000 0.000 0.00
##   I1 0.000 0.000 0.149 0.604 0.000 0.000 0.000 0.00
##   I2 0.000 0.000 0.000 0.235 0.560 0.000 0.000 0.00
##   SA 0.000 0.000 0.000 0.000 0.225 0.678 0.000 0.00
##   A1 0.000 0.000 0.000 0.000 0.000 0.249 0.851 0.00
##   A2 0.000 0.000 0.000 0.000 0.000 0.000 0.016 0.86

The numbers in the matrix (called matrix elements or transitions) describe the probability of moving FROM stages in each column TO stages in each row, within the time interval chosen. For example, for this desert tortoise matrix, in any year a subadult (stage 6) has approimately 24.9% probability of becoming an adult (stage 7): this may be called a growth or progression transition. Likewise, in any year a subadult has about 67.8% chance of staying a subadult: this is called a stasis transition. This means that 100 - (67.8 + 24.9) = 7.3% of subadults die every year. There are different types of transitions: in this matrix there are also fecundity transitions which describe offspring production, and subadults produce on average 1.3 offspring per year. Other species may have different transitions, including skipping stages through fast growth, shrinkage or fission (especially in modular organisms, e.g. most plants, corals), or asexual reproduction.

Matrix elements combine underlying vital rates such as survival, growth and reproduction. For example, the subadult to adult transition (24.9%) combines probability of growing to adult size in one year, and probability of surviving the year. The subadult fecundity (1.3) combines the average number of offspring produced by subadults per year, and probability that those offspring survive the year.