simulate_dynamic_binomial: Simulate a binomial dynamic series

View source: R/simulate.R

simulate_dynamic_binomialR Documentation

Simulate a binomial dynamic series

Description

Generates a latent logit process (random walk or AR(1)) and binomial counts, optionally with structural (zero-inflation) zeros.

Usage

simulate_dynamic_binomial(
  n,
  sigma,
  trials,
  logit0 = 0,
  zero_inflation = 0,
  rho = 1,
  mu = 0,
  offset = 0,
  seed = NULL
)

Arguments

n

Number of observations.

sigma

Standard deviation of the latent increments (Gaussian).

trials

Number of trials: a single number (recycled) or a length-n vector.

logit0

Initial logit z_1. Default 0.

zero_inflation

Structural-zero probability. With probability zero_inflation an observation is forced to a structural zero (gate closed) regardless of the binomial draw. Default 0 (no inflation).

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 offset on the logit scale (length 1 or n); the success probability is \mathrm{logit}^{-1}(\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 (successes), trials, logit (latent path z_t), prob (plogis(offset + logit)), offset, and structural (logical, TRUE for structural zeros).

Examples

sim <- simulate_dynamic_binomial(n = 50, sigma = 0.15, trials = 40, seed = 1)
head(sim$y)
# with structural zeros:
zi <- simulate_dynamic_binomial(50, 0.15, trials = 40, zero_inflation = 0.2, seed = 1)
mean(zi$structural)

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