simulate_dynamic_poisson: Simulate a Poisson dynamic series

View source: R/simulate.R

simulate_dynamic_poissonR Documentation

Simulate a Poisson dynamic series

Description

Generates a latent log-rate process (random walk or AR(1)) and Poisson counts, optionally with zero inflation.

Usage

simulate_dynamic_poisson(
  n,
  sigma,
  log_rate0 = 1,
  zero_inflation = 0,
  rho = 1,
  mu = 0,
  offset = 0,
  seed = NULL
)

Arguments

n

Number of observations.

sigma

Standard deviation of the latent increments (Gaussian).

log_rate0

Initial log-rate z_1. Default 1.

zero_inflation

Probability that the gate is closed (i.e. the probability of a structural zero) at each time point. 0 (default) gives an ordinary Poisson series.

rho

AR(1) coefficient of the latent process z_t = \mu + \rho z_{t-1} + \varepsilon_t. Default 1 (a random walk).

mu

Drift (random walk) / intercept (AR(1)) of the latent process. Default 0.

offset

Known log-exposure offset (length 1 or n); the Poisson mean is \exp(\mathrm{offset}_t + z_t). Default 0.

seed

Optional random seed. The previous state of the global random number generator is restored afterwards.

Value

A list with components y (observed counts), log_rate (the latent log-rate path z_t), rate (the mean exp(offset + log_rate)), offset, and structural (logical, TRUE where a structural zero was forced).

Examples

sim <- simulate_dynamic_poisson(n = 50, sigma = 0.2, log_rate0 = 2,
                           zero_inflation = 0.2, seed = 1)
table(sim$y == 0, sim$structural)

DynCount documentation built on Sept. 28, 2026, 5:10 p.m.