The modeller defines the biological programme; OpenPVA supplies the execution engine, reusable processes, scientific contracts, and reproducible analysis machinery.
OpenPVA is a composable, individual-based Population Viability Analysis (PVA) engine written in pure base R. Instead of locking your species into a fixed menu-driven lifecycle, you write an explicit, ordered lifecycle: either as readable steps over your own parameter, vital-rate and cohort tables (pva_model() |> step_*()), or as ordinary R processes that declare what they read, write, and create. Both routes give the same process objects, and the engine protects interval time, individual IDs, exact pedigree inbreeding, cohort accounting, and bit-identical parallel random streams.
Real OpenPVA output (scripts/make_readme_hero.R): 300 paired replicates of an island population with AR(1) environmental variation, cyclones, exact pedigree inbreeding depression, minimum-kinship mating, and imperfect biennial surveys (p = 0.70) triggering adaptive releases.
- Inputs apart from the lifecycle:
pva_model()takes parameter-evidence, vital-rate and cohort tables;step_*()adds ordered steps whose rules are short formulas such as~ rate("p_surv"). Every name is checked when the model is compiled, anddescribe_model()shows where each input goes before anything runs. - Transparent, ordered biology: A lifecycle is a plain R list of
pva_process()objects. Repeat, reorder, omit, or add custom processes without touching the engine controller. - Engine-owned scientific invariants: Strict validation after every process reconciles births, deaths, removals, introductions, and cohort stocks; preassigned L'Ecuyer-CMRG streams make serial, fork, and PSOCK parallel runs bit-identical.
- Exact genetics & adaptive management out of the box: Exact conditional pedigree inbreeding (dense matrix with automatic switch to level-batched sparse ancestor tracing), non-perturbing neutral-locus gene drop, kinship-aware and seasonal mating with cross-interval sire retention, and isolated-stream imperfect surveys driving management quotas.
- Pure base R, zero runtime dependency bloat:
NeedsCompilation: no,R (>= 4.1.0), and only base/recommended packages at runtime.
OpenPVA is pure base R (no C/C++ compiler required). Install the latest release directly from GitHub with devtools, remotes, or pak:
# Using devtools (or remotes::install_github("BWBrook/OpenPVA"))
devtools::install_github("BWBrook/OpenPVA")
# Build the local vignettes too (cookbook, workflow, rosetta; requires litedown)
devtools::install_github("BWBrook/OpenPVA", build_vignettes = TRUE)
# Or install with pak, or pin a specific release tag
# pak::pak("BWBrook/OpenPVA")
# devtools::install_github("BWBrook/OpenPVA@v2.4.0")Or install directly from a local checkout:
R CMD INSTALL .Build, audit, run, and plot a two-sex stochastic PVA from three small tables and an ordered list of steps, with no functions to write:
library(OpenPVA)
rates <- data.frame(
age = c("0", "1", "2+"), sex = "All",
p_surv = c(0.52, 0.88, 0.88), p_breed = c(0, 0, 1), litter = c(0, 0, 1.2)
)
model <- pva_model(
params = list(maturity = 2, capacity = 80),
rates = rates,
init = data.frame(age = 3, sex = c("F", "M"), n = 10),
n_steps = 20, name = "minimal-example"
) |>
step_survival(~ rate("p_surv") * ceiling_density_multiplier(N, capacity)) |>
step_age() |>
step_reproduction(~ rate("p_breed"), litter_poisson(~ rate("litter")),
offspring_sex_bernoulli(0.5), mate = mate_random(~ age >= maturity)) |>
step_census()
plot(model) # lifecycle diagram, before anything runs
describe_parameters(model) # where every input goes
result <- model |> compile_scenario(n_runs = 200, seed = 2026) |> run_scenario()
summarise_pva(result, threshold = 10)
all(summarise_accounting(result)$reconciled)
plot(result, type = "trajectory", threshold = 10)
# compare options on paired seeds: design columns override parameters by name
run_pva_ensemble(data.frame(capacity = c(40, 80, 160)), model,
n_runs = 200, seed = 2026, seed_by = TRUE)A formula may use your parameters, the population fields (age, sex, ...), globals written by earlier steps, time, N and rate("<column>"). A misspelled name, an override that cannot matter, or a rate table with a gap stops at compile_scenario() with a message naming the step.
The model compiles to ordinary pva_process() objects, and the native API remains first-class. Custom biological or management rules compose through the exact same contract, with no registration, and step_process() drops one into an authored pipeline at any position:
harvest_oldest <- pva_process(
name = "harvest_oldest",
run = function(state, context, params) {
if (!length(state$population$id)) return(pva_result(state))
oldest <- which.max(state$population$age)
state$population$alive[oldest] <- FALSE
pva_result(state, pva_events("removal", length(oldest), "harvest"))
},
requires = "population.age",
writes = "population.alive"
)
hunted <- pva_model(list(maturity = 2), rates,
data.frame(age = 3, sex = c("F", "M"), n = 10), n_steps = 20) |>
step_survival(~ rate("p_surv")) |>
step_process(harvest_oldest) |>
step_age() |>
step_reproduction(~ rate("p_breed"), litter_poisson(~ rate("litter")),
offspring_sex_bernoulli(0.5), mate = mate_random(~ age >= maturity)) |>
step_census()
# the same lifecycle written directly as a process list
scenario <- scenario_spec(
name = "hand-written", n_runs = 200, n_steps = 20, seed = 2026,
init_fun = function() pva_population(sex = rep(c("F", "M"), each = 10), age = 3),
processes = list(
survival_process(age_sex_rate(rates, "p_surv")),
harvest_oldest,
age_process(),
reproduction_process(age_sex_rate(rates, "p_breed"), litter_poisson(age_sex_rate(rates, "litter")),
offspring_sex_bernoulli(0.5),
mate = mate_random(function(pop, state, context, params) pop$age >= 2)),
census_process()
),
initial_census = census_process()
)If a custom process forgets its removal event or mutates an undeclared field, strict validation halts immediately and names the process.
| Ecological layer | Key building blocks |
|---|---|
| Model authoring & audit | pva_model(), cohort_population(), step_survival(), step_reproduction(), step_environment() and 12 more step_*(), step_process(), compile_scenario(), describe_model(), describe_parameters() |
| State & cohorts | pva_population(), pva_state() (pedigree, n_loci, mate_field), add_individuals() |
| Demography & mating | survival_process(), staged_survival_process(), age_process(), reproduction_process(), pairing_process(), mating_process(), mate_random(), mate_min_kinship(), mate_from_field() |
| Environment & space | environment_process(), env_ar1(), spatial_correlation(), env_trend(), catastrophe_process(), dispersal_process(), markov_dispersal_process(), shift_logit(), qbeta_norm() |
| Management & MSE | removal_process(), ceiling_process(), introduction_process(), assign_process(), survey_process() (isolated substream 5), survey_quota() |
| Genetics & life tables | kinship_matrix(), mean_kinship(), summarise_pedigree(), summarise_markers(), marker_founder_shares(), genetic_metrics(), inbreeding_multiplier(), inbreeding_proxy_process(), life_table_metrics() |
| Execution, summaries & plots | scenario_spec(), run_scenario(), run_pva_ensemble(), summarise_pva() (risk, EMA, MCSE), summarise_trajectory(), summarise_accounting(), describe_lifecycle(), format_lifecycle(), plot() |
- Online documentation site: bwbrook.github.io/OpenPVA (grouped reference for all 82 exports, rendered vignettes & changelog)
- Model-building cookbook:
vignette("cookbook", package = "OpenPVA")(tables and ordered steps, no functions: density, inbreeding, seasons, patches, surveys, paired ensembles and the escape hatch) - Visual workflow walkthrough:
vignette("workflow", package = "OpenPVA")(lifecycle diagrams, life-table checks, accounting, adaptive surveys, ensembles & genetics) - GAPPS / Vortex / Leslie translation guide:
vignette("rosetta", package = "OpenPVA") - Agent modelling guide: For AI agents & script authors
- Grizzly bear seasonal lifecycle: summer mating (
mating_process()), autumn harvest and winter birth within one annual interval, so a sire shot after mating still fathers the litter, plus 3-year maternal dependency. (Sire retention across intervals is shown by the seasonal herd invignette("rosetta").) — Grizzly model - Lord Howe Island woodhen recovery: sex-specific survival, shared environmental stochasticity, territorial pairing, captive releases, and parameter-evidence table — Woodhen model
- Design & heritage documents: Vision and scope · Lifecycle-process contract · Public API · GAPPS heritage · GAPPS evidence review
If you use OpenPVA in research or conservation assessments, please cite the software archive (Zenodo Concept DOI 10.5281/zenodo.24521838) or run citation("OpenPVA") in R.
Rscript --vanilla scripts/run_tests.R # install to temp library and run all tests
Rscript --vanilla scripts/build_rd.R # regenerate man/*.Rd from scripts/rd_topics.R
R CMD build . && R CMD check --as-cran OpenPVA_*.tar.gzDocumentation is generated directly from live function formals via scripts/build_rd.R (roxygen2 is not required); building the vignette requires the suggested package litedown.

