## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 7,
  fig.height = 4
)

## -----------------------------------------------------------------------------
library(demovuln)

## -----------------------------------------------------------------------------
A <- matrix(
  c(0.0, 0.4,
    2.0, 0.7),
  nrow = 2,
  byrow = FALSE
)

A

## -----------------------------------------------------------------------------
model <- matrix_population_model(
  A,
  adult_stages = 2,
  juvenile_stages = 1
)

## -----------------------------------------------------------------------------
sim <- simulate_dynamics(
  model,
  target = "adult_survival",
  magnitude = 0.25,
  duration = 1,
  period = 3,
  t_max = 50,
  recovery_steps = 10
)

sim$reduction

## -----------------------------------------------------------------------------
plot(
  sim$baseline_abundance,
  type = "l",
  lwd = 2,
  xlab = "Time step",
  ylab = "Relative population size",
  ylim = range(c(sim$baseline_abundance, sim$abundance))
)

lines(sim$abundance, lwd = 2, lty = 2)

legend(
  "topright",
  legend = c("Baseline", "Perturbed"),
  lty = c(1, 2),
  lwd = 2,
  bty = "n"
)

