README.md

msPVA : An R implementation of count-based multi-site population viability analysis

DOI Build Status

This package implements a stochastic simulation for a count-based multi-site population viability analysis as described in chapter 11 of Quantitative Conservation Ecology (Morris & Doak, 2002).

Code is highly inspired from the MatLab implementation described in the book.

Installation

You have two options here.

Install package from github.com

This allows you to easily install updates, have access to the function help files etc.

library(devtools)
devtools::install_github("cmartin/msPVA")
library(msPVA)

Or you download the source file and run it directly

In this case, you need download the raw R file and then execute :

source("MultisitePVA.R")

This is a quicker, but dirtier way!

Try some examples

With the same Clapper rail data as in Morris & Doak

Definining parameters manually :

res <- simulate_ms_pva(
 leaving_prob = 0.2,
 reaching_prob = 0.5,
 growth_rate_means = c(0.043, -0.002, 0),
 growth_rate_vars = c(0.051, 0.041, 0.051),
 initial_pops = c(70, 26, 33),
 growth_rate_corrs = {matrix(
   c(   1.000,  0.995,   0.896,
   0.995,   1.000,   0.938,
   0.896,   0.938,   1.000),
   nrow = 3,
   ncol = 3,
   byrow = TRUE
 )},
 K = c(286, 60, 58),
 quasi_extinction_thresholds = c(20, 20, 20),
 n_years = 50,
 n_runs = 100,
 with_progress_bar = FALSE

)

print(res)
This is the deterministic lambda value :  1.0319573564599
And this is the mean stochastic lambda :  0.99642732192589
Below is mean and standard deviation of log lambda :
-0.00367530129674074 0.013982886113063
hist(res)

plot(res)

Or ask the package to calculate most of them automatically from a time-series :

With a two-populations polar bear time series from Stirling et al. 2004

params <- calculate_params_from_file(
 system.file("extdata", "PolarBear_Stirling2004.csv", package = "msPVA")
)
Warning in calculate_params_from_file(system.file("extdata", "PolarBear_Stirling2004.csv", : There were gaps in the time series.
  Mean and variance were computed by linear regression.
  Correlation matrix was calculated assuming regular intervals.
res <- do.call(
 "simulate_ms_pva",
 c(
   params,
   list(
     K = c(300,200),
     leaving_prob = 0.1,
     reaching_prob = 0.7,
     quasi_extinction_thresholds = c(20, 20),
     n_years = 50,
     n_runs = 100,
     with_progress_bar = FALSE
   )
 )
)
print(res)
This is the deterministic lambda value :  1.05786392886293
And this is the mean stochastic lambda :  0.990314335670581
Below is mean and standard deviation of log lambda :
-0.00978931640713308 0.0107011693034957

Run it for a single population

# From a precalculated mean log-lambdas

res <- simulate_ss_pva(
 growth_rate_means = 0.043,
 growth_rate_vars = 0.051,
 initial_pops = 70,
 K = 286,
 quasi_extinction_thresholds = 20,
 n_years = 50,
 n_runs = 100
)

print(res)
Over a 50 years span, the extinction risk of this population is 0.1
And the risk of decline is 0.16
hist(res)

# From a vector of log-lambdas
res <- simulate_ss_pva(
  log_lambdas = c(-0.0503626618483076, -0.0316522478682412, -0.205890697055539,
                  -0.0407897021414208, 0.151024474883104, -0.141017433696716, 0.105149579850484,
                  0.104087724782143, 0.18297223483855),
  initial_pops = 70,
  K = 286,
  quasi_extinction_thresholds = 20,
  n_years = 50,
  n_runs = 100
)

Read the book

If you are to use this package, I highly recommend that you first read chapter 11 from Quantitative Conservation Ecology (Morris & Doak, 2002), so you understand limitations and assumptions from the underlying model. Managing animal populations should not be taken lightly.

Problems

Please report any bugs to the GitHub issue tracker and write any questions to charles.martin1@uqtr.ca

Citation

If this code is useful to you, please cite as :

Charles A. Martin (2016). msPVA: An R implementation of count-based multi-site population viability
analysis. R package version 0.0.0.9005. https://github.com/cmartin/msPVA. DOI:10.5281/zenodo.34692


cmartin/PopulationViabilityAnalysis documentation built on May 13, 2019, 8:23 p.m.