## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(redlist)

## ----two-point-exp------------------------------------------------------------
rl_reduction(
  population = c(20000, 14000),
  time = c(1961, 1981),
  generation_length = 20,
  model = "exponential",
  assessment_year = 2001
)

## ----two-point-lin------------------------------------------------------------
rl_reduction(
  population = c(20000, 14000),
  time = c(1961, 1981),
  generation_length = 20,
  model = "linear",
  assessment_year = 2001
)

## ----multi--------------------------------------------------------------------
years <- 2000:2020
counts <- round(10000 * 0.97^(0:20))
rl_reduction(counts, years, generation_length = 7)

## ----subcriterion-------------------------------------------------------------
r <- rl_reduction(c(20000, 14000), c(1961, 1981),
                  generation_length = 20, assessment_year = 2001)
c(A2 = r$category_a,
  A1 = rl_reduction(c(20000, 14000), c(1961, 1981),
                    generation_length = 20, assessment_year = 2001,
                    subcriterion = "A1")$category_a)

## ----c1-----------------------------------------------------------------------
# a one generation decline for the Vulnerable threshold under C1
rl_reduction(counts, years, generation_length = 7, years = 7)

## ----overall------------------------------------------------------------------
overall <- rl_overall_reduction(
  past = c(10000, 8000, 12000),
  present = c(5000, 9000, 2000),
  subpopulation = c("Pacific", "Atlantic", "Indian")
)
overall

## ----overall-parts------------------------------------------------------------
attr(overall, "subpopulations")

## ----overall-mixed------------------------------------------------------------
rl_overall_reduction(
  present = c(4403, 9074, 1312),
  reduction = c(0.50, -0.179, 0.70)
)

