Skip to contents

Simulates a stochastic birth-death process over multiple time steps. The process models population dynamics where both birth and death rates can vary over time.

Usage

sim_stochastic_exponential(n0, lambda, mu, steps, delta_t)

Arguments

n0

Numeric value indicating the initial population size. Must be a non-negative integer.

lambda

Numeric vector of birth rates. This can be a single value (constant birth rate) or a vector of length steps specifying the birth rate at each time step.

mu

Numeric vector of death rates. This can be a single value (constant death rate) or a vector of length steps specifying the death rate at each time step.

steps

Integer value specifying the number of time steps to simulate. Must be a non-negative integer.

delta_t

Numeric vector of time step sizes. This can be a single value (constant time step) or a vector of length steps. If a single value is provided, it is replicated for each time step.

Value

A tibble with columns:

  • time: The cumulative time at each step.

  • count: The population size at each time step.

  • group: A factor indicating the group of contiguous intervals where the birth and death rates are constant.