Package 'bbousims'

Title: Simulate Boreal Caribou Survival, Recruitment and Population Growth
Description: Simulates survival and recruitment data for boreal caribou populations using hierarchical Bayesian models.
Authors: Seb Dalgarno [aut, cre] , Joe Thorley [aut] , John Boulanger [aut] , Ayla Pearson [aut], Environment and Climate Change Canada [cph]
Maintainer: Seb Dalgarno <[email protected]>
License: Apache License (== 2.0) | file LICENSE
Version: 0.1.0
Built: 2024-11-29 04:26:31 UTC
Source: https://github.com/poissonconsulting/bbousims

Help Index


Stochastic matrix multiplication for age-structured population projection.

Description

Matrix x should be a process matrix with identical number of rows and columns. Matrix y should have one column, with each row indicating abundance at a given stage. The number of rows must be identical to the number of columns in x. A binomial distribution is used, where size is drawn from the y matrix and prob is drawn from the x matrix.

Usage

x %*b% y

Arguments

x

A matrix with identical number of rows and columns.

y

A vector or matrix with one column.

Value

A vector of the projected abundance for each stage.

Examples

population0 <- c(148, 82, 111, 99)
survival_mat <- bbs_matrix_survival(c(0.845, 0.872, 0.859, 0.861))
survival_mat %*b% population0

Stochastic matrix multiplication for age-structured population projection.

Description

Matrix x should be a process matrix with identical number of rows and columns. Matrix y should have one column, with each row indicating abundance at a given stage. The number of rows must be identical to the number of columns in x. A binomial distribution is used, where size is drawn from the y matrix and prob is drawn from the x matrix.

Usage

x %*b2% y

Arguments

x

A matrix with identical number of rows and columns.

y

A vector or matrix with one column.

Value

A vector of the projected abundance for each stage.

Examples

population0 <- c(148, 82, 111, 99)
survival_mat <- bbs_matrix_survival(c(0.845, 0.872, 0.859, 0.861))
survival_mat %*b% population0

Demographic summary

Description

Generate calf-cow ratio, DeCesare recruitment, lambda, leslie matrix and stable-stage distribution from demographic parameters.

Usage

bbs_demographic_summary(
  calves_per_adult_female = 0.7,
  survival_adult_female = 0.85,
  survival_calf = 0.5,
  survival_yearling = survival_adult_female,
  proportion_female = 0.5
)

Arguments

calves_per_adult_female

A number of the calves per adult female.

survival_adult_female

A number between 0 and 1 of the annual female adult survival.

survival_calf

number between 0 and 1 of the annual calf survival.

survival_yearling

A number between 0 and 1 of the annual yearling survival.

proportion_female

A number between 0 and 1 indicating the proportion of recruits that are female.

Value

A named list of the calf-cow ratio, DeCesare recruitment, leslie matrix, lambda estimate and stable-stage distribution.

Examples

bbs_demographic_summary()

Get stochastic fecundity rates by year and stage.

Description

Year is scaled to Year - 1 for trend, which ensures that the intercept is the rate in the first year.

Usage

bbs_fecundity(
  intercept,
  trend = rep(0, length(intercept)),
  annual_sd = rep(0, length(intercept)),
  nyear = 10
)

Arguments

intercept

A vector of the intercept of the log-odds fecundity by stage. If NA, fecundity is set to 0 for all years.

trend

A vector of the effect of an increase of one year on the log-odds fecundity by stage.

annual_sd

A vector of the standard deviation of the annual variation on the log-odds fecundity by stage.

nyear

A whole number of the number of years.

Value

A matrix of fecundity rates with dimensions year and stage.

Examples

bbs_fecundity(c(NA, logit(0.4)), trend = c(NA, 0.1), annual_sd = c(NA, 0.05))

Get stochastic Boreal Caribou fecundity rates by year and stage.

Description

Year is scaled to Year - 1 for trend, which ensures that calves_per_adult_female is the rate in the first year.

Usage

bbs_fecundity_caribou(
  calves_per_adult_female,
  trend = 0,
  annual_sd = 0,
  nyear = 10
)

Arguments

calves_per_adult_female

A number of the calves per adult female.

trend

A number of the effect of an increase of one year on the log-odds calves per adult female.

annual_sd

A number of the standard deviation of the annual variation on the log-odds calves per adult female.

nyear

A whole number of the number of years.

Value

A matrix of fecundity rates with dimensions year and stage.

Examples

bbs_fecundity_caribou(0.4, trend = 0.1, annual_sd = 0.3)

Create an age process matrix.

Description

Create an age process matrix.

Usage

bbs_matrix_age(age = c(2, 3, 3))

Arguments

age

A vector indicating the stage to age into. If ageing does not occur, the stage should reference itself.

Value

A matrix of the age subprocess.

Examples

bbs_matrix_age(c(2, 3, 3)) %*% c(80, 50, 150)

Create a birth process matrix.

Description

Create a birth process matrix.

Usage

bbs_matrix_birth(
  fecundity,
  female_recruit_stage = 1,
  male_recruit_stage = NULL,
  proportion_female = 0.5
)

Arguments

fecundity

A vector of the fecundity rates in each stage.

female_recruit_stage

A positive whole number of the stage representing female recruits.

male_recruit_stage

A positive whole number of the stage representing male recruits. Ignored if NULL.

proportion_female

A number between 0 and 1 indicating the proportion of recruits that are female.

Value

A birth process matrix.

Examples

bbs_matrix_birth(c(0, 0, 0.2, 0, 0.25, 0)) %*% rep(100, 6)

Create a birth process matrix for each year.

Description

Create a birth process matrix for each year.

Usage

bbs_matrix_birth_year(
  fecundity,
  female_recruit_stage = 1,
  male_recruit_stage = NULL,
  proportion_female = 0.5
)

Arguments

fecundity

A matrix of the fecundity rates with dimensions year and stage.

female_recruit_stage

A positive whole number of the stage representing female recruits.

male_recruit_stage

A positive whole number of the stage representing male recruits. Ignored if NULL.

proportion_female

A number between 0 and 1 indicating the proportion of recruits that are female.

Value

An array of the birth process matrices with dimensions stage, stage, year.

Examples

fec <- bbs_fecundity(c(NA, 0.7), nyear = 3)
bbs_matrix_birth_year(fec$eFecundity)

Create a survival process matrix.

Description

Create a survival process matrix.

Usage

bbs_matrix_survival(survival)

Arguments

survival

A vector of the survival rates in each stage.

Value

A matrix of the survival subprocess.

Examples

bbs_matrix_survival(c(0.5, 0.83, 0.84)) %*% rep(100, 3)

Create survival matrix for each year and period.

Description

Create survival matrix for each year and period.

Usage

bbs_matrix_survival_period(survival)

Arguments

survival

An array of the survival rates with dimensions period, year and stage. Period represents any subdivision of a year (i.e., week, month, season).

Value

An array of survival process matrices with dimensions stage, stage, year, period.

Examples

survival_rates <- bbs_survival(logit(c(0.94, 0.98)), nyear = 2, nperiod_within_year = 1)
bbs_matrix_survival_period(survival_rates$eSurvival)

Plot Population

Description

Plots population abundance by period and stage.

Usage

bbs_plot_population(x, ...)

## S3 method for class 'data.frame'
bbs_plot_population(x, annual = TRUE, ...)

## S3 method for class 'bbou_population'
bbs_plot_population(x, annual = TRUE, nperiod_within_year = 12, ...)

## S3 method for class 'bbou_simulation'
bbs_plot_population(x, annual = TRUE, alpha = 0.5, ...)

## S3 method for class 'bbou_population_caribou'
bbs_plot_population(x, annual = TRUE, ...)

Arguments

x

The object.

...

Unused parameters.

annual

A flag indicating whether to show annual population (as opposed to monthly).

nperiod_within_year

A whole number of the number of periods in a year.

alpha

A number between 0 and 1 of the point transparency.

Value

A ggplot object.

A ggplot object.

A ggplot object.

A ggplot object.

Methods (by class)

  • bbs_plot_population(data.frame): Plot population abundance by period and stage for a data frame (abundance data.frame in output bbs_simulate_caribou()).

  • bbs_plot_population(bbou_population): Plot population abundance by period and stage for a matrix (output of bbs_population_caribou()).

  • bbs_plot_population(bbou_simulation): Plot population abundance by period and stage for a matrix (output of bbs_simulate_caribou()).

  • bbs_plot_population(bbou_population_caribou): Plot population abundance by period and stage for a matrix (output of bbs_simulate_caribou()).

Examples

survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
x <- bbs_simulate_caribou(survival, fecundity = fecundity)
bbs_plot_population(x[[1]]$abundance)
pop0 <- c(100, 200)
survival <- bbs_survival(intercept = logit(c(0.95, 0.98)))
fecundity <- bbs_fecundity(intercept = c(NA, logit(0.4)))
survival_mat <- bbs_matrix_survival_period(survival$eSurvival)
birth_mat <- bbs_matrix_birth_year(fecundity$eFecundity)
age_mat <- bbs_matrix_age(c(2, 2))
x <- bbs_population(pop0,
  birth = birth_mat,
  age = age_mat,
  survival = survival_mat
)
bbs_plot_population(x)
survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
x <- bbs_simulate_caribou(survival, fecundity = fecundity, nsims = 3)
bbs_plot_population(x, alpha = 0.7)
survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
x <- bbs_population_caribou(survival, fecundity = fecundity)
bbs_plot_population(x)

Simulate population from survival, ageing and birth

Description

Simulate population projections given initial population in each stage and survival, ageing, and birth process matrices. Survival can vary by period (e.g., month) and year, birth can vary by year, and ageing is constant. This model assumes that survival occurs at the end of each period and survival, ageing and birth occur at the end of each year, in that order. The dimensions of birth, age and survival process matrices must be identical to the length of the initial population vector.

Usage

bbs_population(population_init, birth, age, survival, stochastic = TRUE)

Arguments

population_init

A vector of the initial population for each stage.

birth

An array of the birth matrices (output of bbs_matrix_birth_year()).

age

An age process matrix (output of bbs_matrix_age).

survival

An array of the survival matrices (output of bbs_matrix_survival_period()).

stochastic

A flag indicating whether to include demographic stochasticity.

Value

A matrix of the population by stage and period.

Examples

pop0 <- c(100, 200)
survival <- bbs_survival(intercept = logit(c(0.95, 0.98)))
fecundity <- bbs_fecundity(intercept = c(NA, logit(0.4)))
survival_mat <- bbs_matrix_survival_period(survival$eSurvival)
birth_mat <- bbs_matrix_birth_year(fecundity$eFecundity)
age_mat <- bbs_matrix_age(c(2, 2))
x <- bbs_population(pop0,
  birth = birth_mat,
  age = age_mat,
  survival = survival_mat
)

Simulate Boreal Caribou population from survival, ageing and birth.

Description

Simulate population projection for Boreal Caribou from key survival and fecundity rates.

Usage

bbs_population_caribou(
  survival,
  fecundity,
  adult_females = 1000,
  proportion_adult_female = 0.65,
  proportion_yearling_female = 0.5,
  stochastic = TRUE
)

Arguments

survival

A list of the Caribou survival rates (output of bbs_survival_caribou())

fecundity

A list of the Caribou fecundity rates (output of bbs_fecundity_caribou())

adult_females

A number of the initial number of adult females in the population.

proportion_adult_female

A number between 0 and 1 of the proportion of adults that are female.

proportion_yearling_female

A number between 0 and 1 of the proportion of yearlings that are female.

stochastic

A flag indicating whether to include demographic stochasticity.

Details

This model assumes that survival occurs at the end of each period and survival, ageing and birth occur at the end of each year, in that order. Initial population size for all stages is determined from the initial number of adult females and the calculated stable stage distribution. Survival and fecundity arguments accept outputs of bbs_survival_caribou() and bbs_fecundity_caribou(). These are converted into processes matrices using bbs_matrix_survival_period() and bbs_matrix_birth_year() prior to projection. bbs_population() is called internally to project population. Yearling female survival is assumed to be the same as adult female survival. Stages 1-6 in output matrix correspond to female calf, male calf, female yearling, male yearling, female adult and male adult, respectively.

Value

A matrix of the population by stage and period.

Examples

survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
x <- bbs_population_caribou(survival, fecundity = fecundity)

Assign population into groups

Description

In each period the population is assigned into groups. Group sizes are drawn randomly from a gamma-poisson distribution with specified lambda and theta. Group sizes are drawn until the cumulative size exceeds the total individuals. The remaining individuals comprise the final group. If the remaining number of individuals is < min_size specified, these will be added to the previous group. Groups are filled by drawing individuals randomly.

Usage

bbs_population_groups(
  population,
  group_size_lambda = 5,
  group_size_theta = 2,
  group_max_proportion = 1/4,
  group_min_size = 2
)

Arguments

population

A matrix of the population by stage and period (output of bbs_population() or bbs_population_caribou()).

group_size_lambda

A number of the lambda value of the gamma-poisson distribution to draw group sizes from.

group_size_theta

A number of the theta value of the gamma-poisson distribution to draw group sizes from.

group_max_proportion

A number between 0 and 1 of the maximum group size as proportion of the total population.

group_min_size

A whole positive number of the minimum group size.

Value

A list of groups in each period.

Examples

survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
x <- bbs_population_caribou(survival, fecundity = fecundity, adult_females = 100)
bbs_population_groups(x)

Assign population into groups by pairs

Description

In each period the population is assigned into groups. Calf-cow pairs are created and assigned to groups together. Group sizes are drawn randomly from a gamma-poisson distribution with specified lambda and theta. Group sizes are drawn until the cumulative size exceeds the total individuals. The remaining individuals comprise the final group. If the remaining number of individuals is < min_size specified, these will be added to the previous group. Groups are filled by drawing pairs or individuals from the pool. If there is only space for one individual left in a group, the pool of individuals (i.e., not pairs) will be sampled. If there are only pairs left in the pool and one individual is required to fill a group, a pair will be broken up.

Usage

bbs_population_groups_pairs(
  population,
  group_size_lambda = 5,
  group_size_theta = 2,
  group_max_proportion = 1/4,
  group_min_size = 2,
  recruit_stages = c(1, 2),
  reproductive_female_stages = c(3, 5)
)

Arguments

population

A matrix of the population by stage and period (output of bbs_population() or bbs_population_caribou()).

group_size_lambda

A number of the lambda value of the gamma-poisson distribution to draw group sizes from.

group_size_theta

A number of the theta value of the gamma-poisson distribution to draw group sizes from.

group_max_proportion

A number between 0 and 1 of the maximum group size as proportion of the total population.

group_min_size

A whole positive number of the minimum group size.

recruit_stages

A vector of whole numbers indicating the recruit stages (e.g., calf).

reproductive_female_stages

A vector of whole numbers indicating the reproductive female stages (e.g., cows).

Value

A list of groups for each period.

Examples

survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
x <- bbs_population_caribou(survival, fecundity = fecundity, adult_females = 100)
bbs_population_groups_pairs(x)

Assign population into groups for each composition survey

Description

See bbs_population_groups() for details on group assignment. Groups are sampled in each composition survey in proportion to group_coverage.

Usage

bbs_population_groups_survey(
  population,
  month_composition = 9,
  group_size_lambda = 5,
  group_size_theta = 2,
  group_max_proportion = 1/4,
  group_min_size = 2,
  group_coverage = 0.2
)

Arguments

population

A matrix of the population by stage and period (output of bbs_population() or bbs_population_caribou()).

month_composition

A whole number between 1 and 12 of the month that composition surveys take place, relative to the start of the biological year.

group_size_lambda

A number of the lambda value of the gamma-poisson distribution to draw group sizes from.

group_size_theta

A number of the theta value of the gamma-poisson distribution to draw group sizes from.

group_max_proportion

A number between 0 and 1 of the maximum group size as proportion of the total population.

group_min_size

A whole positive number of the minimum group size.

group_coverage

A number between 0 and 1 of the proportion of groups sampled.

Value

A list of observed groups in each composition survey.

Examples

survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
x <- bbs_population_caribou(survival, fecundity = fecundity, adult_females = 100)
bbs_population_groups_survey(x, group_coverage = 0.1)

Simulate Boreal Caribou Data

Description

Simulate Boreal Caribou data from survival rates, fecundity rates and sampling parameters.

Usage

bbs_simulate_caribou(
  survival,
  fecundity,
  nsims = 1,
  adult_females = 500,
  proportion_adult_female = 0.65,
  proportion_yearling_female = 0.5,
  probability_unsexed_adult_female = 0,
  probability_unsexed_adult_male = 0,
  month_composition = 9L,
  group_size = 5,
  group_coverage = 0.3,
  group_min_size = 2,
  group_max_proportion = 1,
  collared_adult_females = 30,
  month_collar = 1L,
  probability_uncertain_mortality = 0,
  probability_uncertain_survival = 0,
  population_name = "A"
)

Arguments

survival

A list of the Caribou survival rates (output of bbs_survival_caribou())

fecundity

A list of the Caribou fecundity rates (output of bbs_fecundity_caribou())

nsims

A whole positive number of the number of simulations.

adult_females

A number of the initial number of adult females in the population.

proportion_adult_female

A number between 0 and 1 of the proportion of adults that are female.

proportion_yearling_female

A number between 0 and 1 of the proportion of yearlings that are female.

probability_unsexed_adult_female

A number between 0 and 1 of the probability that an adult female is unsexed.

probability_unsexed_adult_male

A number between 0 and 1 of the probability that an adult male is unsexed.

month_composition

A whole number between 1 and 12 of the month that composition surveys take place, relative to the start of the biological year.

group_size

A whole number of the average group size. Group sizes are drawn from a poisson distribution with lambda of group_size.

group_coverage

A number between 0 and 1 of the proportion of groups sampled.

group_min_size

A whole positive number of the minimum group size.

group_max_proportion

A number between 0 and 1 of the maximum group size as proportion of the total population.

collared_adult_females

A whole positive number of the number of collared adult females. The number of collared adult females is 'topped up' each year at month_collar.

month_collar

A whole number between 1 and 12 of the collaring month.

probability_uncertain_mortality

A number between 0 and 1 of the probability of uncertain mortality.

probability_uncertain_survival

A number between 0 and 1 of the probability of uncertain survival.

population_name

A string of the population name. This does not affect simulation but can be used as a unique identifier.

Details

See bbs_survival_caribou() and bbs_fecundity_caribou() for generating survival and fecundity rates. See bbs_population_caribou() for details on how population is simulated. See bbs_population_groups_survey() for details on how groups are assigned for each composition survey. See bbs_survival_collared() for details on how survival of collared adult female is determined.

Survival and recrutiment data.frames generated are formatted to be used as input data to bboutools::bb_fit_survival() and bboutools::bb_fit_recruitment(), respectively.

Value

A list of three tibbles. The first named survival has columns Year, Month, StartTotal, MortalitiesCertain and MortalitiesUncertain. The second named recruitment has columns Year, Month, Cows, Bulls, UnknownAdults, Yearlings and Calves. And the final named abundance has columns Year, Month, Stage, Abundance.

Examples

survival <- bbs_survival_caribou(0.84)
fecundity <- bbs_fecundity_caribou(0.7)
caribou <- bbs_simulate_caribou(survival, fecundity = fecundity, nsims = 2)

Get stochastic survival rates by period, year and stage.

Description

Each stage can vary by intercept, year trend, annual random effect, period random effect and period within annual random effect. All values are provided on the log-odds scale. Variation from random effects is stochastic. Year is scaled to Year - 1 for trend, which ensures that the intercept is the rate in the first year.

Usage

bbs_survival(
  intercept,
  nyear = 10,
  trend = rep(0, length(intercept)),
  annual_sd = rep(0, length(intercept)),
  period_sd = rep(0, length(intercept)),
  annual_period_sd = rep(0, length(intercept)),
  nperiod_within_year = 12
)

Arguments

intercept

A vector of the intercept of the log-odds survival by stage.

nyear

A whole number of the number of years.

trend

A vector of the effect of an increase of one year on the log-odds survival by stage.

annual_sd

A vector of the standard deviation of the annual variation of the log-odds survival by stage.

period_sd

A vector of the standard deviation of the period variation of the log-odds survival by stage.

annual_period_sd

A vector of the standard deviation of the period within annual variation on the log-odds survival by stage.

nperiod_within_year

A whole number of the number of periods in a year.

Value

An array of survival rates with dimensions period, year, stage.

Examples

survival <- bbs_survival(intercept = logit(c(0.94, 0.98, 0.98)), trend = c(0, 0, 0.2))

Get stochastic Boreal Caribou survival rates by month, year and stage.

Description

Stages include female calves, female yearlings and female adults. Calf and adult female survival can vary by trend, annual random effect, month random effect and month within annual random effect. Yearling survival is created as an effect on adult female survival rates. Variation from random effects is stochastic. Year is scaled to Year - 1 for trend, which ensures that the intercept is the rate in the first year.

Usage

bbs_survival_caribou(
  survival_adult_female,
  survival_calf_female = 0.5,
  nyear = 10,
  trend_adult_female = 0,
  annual_sd_adult_female = 0,
  month_sd_adult_female = 0,
  annual_month_sd_adult_female = 0,
  trend_calf_female = 0,
  annual_sd_calf_female = 0,
  month_sd_calf_female = 0,
  annual_month_sd_calf_female = 0,
  yearling_effect = 0
)

Arguments

survival_adult_female

A number between 0 and 1 of the annual female adult survival.

survival_calf_female

A number between 0 and 1 of the annual female calf survival.

nyear

A whole number of the number of years.

trend_adult_female

A number of the effect of an increase of one year on the log-odds adult female monthly survival.

annual_sd_adult_female

A number of the standard deviation of the annual variation in adult female survival on the log-odds monthly survival.

month_sd_adult_female

A number of the standard deviation of the monthly variation in adult female survival on the log-odds monthly survival.

annual_month_sd_adult_female

A number of the standard deviation of the monthly variation within year variation in adult female survival on the log-odds monthly survival.

trend_calf_female

A number of the effect of an increase of one year on the log-odds calf female monthly survival.

annual_sd_calf_female

A number of the standard deviation of the annual variation in calf female survival on the log-odds monthly survival.

month_sd_calf_female

A number of the standard deviation of the monthly variation in calf female survival on the log-odds monthly survival.

annual_month_sd_calf_female

A number of the standard deviation of the monthly variation within year variation in calf female survival on the log-odds monthly survival.

yearling_effect

A number of the effect of yearling on the log-odds adult female monthly survival.

Value

An array of survival rates with dimensions month, year, stage.

Examples

survival <- bbs_survival_caribou(0.84, survival_calf_female = 0.5)

Survival of collared females.

Description

The number of collared adult females is 'topped up' at each month_collar. Survival rates in each month/year determine the number of mortalities. The probability of uncertain mortality determines the proportion of mortalities that are uncertain. The probability of uncertain survival reduces the number of collared adult females without adding mortalities.

Usage

bbs_survival_collared(
  collared_adult_females,
  survival_adult_female_month_year,
  probability_uncertain_mortality = 0,
  probability_uncertain_survival = 0,
  month_collar = 1L,
  population_name = "A"
)

Arguments

collared_adult_females

A whole positive number of the number of collared adult females. The number of collared adult females is 'topped up' each year at month_collar.

survival_adult_female_month_year

A matrix of the female adult survival rates with dimensions month and year.

probability_uncertain_mortality

A number between 0 and 1 of the probability of uncertain mortality.

probability_uncertain_survival

A number between 0 and 1 of the probability of uncertain survival.

month_collar

A whole number between 1 and 12 of the collaring month.

population_name

A string of the population name. This does not affect simulation but can be used as a unique identifier.

Value

A data.frame of the number of collared adult females, certain mortalities and uncertain mortalities in each year and month.

Examples

survival <- bbs_survival_caribou(0.84)
survival_adult_female <- survival$eSurvival[, , 3]
survival_collared <- bbs_survival_collared(
  collared_adult_females = 30,
  survival_adult_female_month_year = survival_adult_female
)

Inverse Logarithmic Transformation

Description

Inverse Logarithmic Transformation

Usage

ilog(x)

Arguments

x

A numeric object.

Examples

ilog(10)