structural_zero_prob: Posterior probability that each observed zero is structural

View source: R/zero-inflation.R

structural_zero_probR Documentation

Posterior probability that each observed zero is structural

Description

For a zero-inflated fit (Poisson or binomial), returns for every observed zero the posterior probability that it is a structural zero (gate closed) rather than an ordinary sampling zero generated by the observation process. A single gate-open probability governs all observations (it does not vary over time or with covariates), while the gate itself is drawn separately for every observation.

Usage

structural_zero_prob(object, zeros_only = TRUE)

Arguments

object

A "dynamic_fit" object fitted with zeros = "inflated" (Poisson or binomial family).

zeros_only

If TRUE (default), return only the rows where the observation is zero; with FALSE, return one row per observation (the non-zero ones with p_structural = 0).

Details

The model introduces a latent gate indicator v_t \in \{0, 1\}: when the gate is open (v_t = 1) the count comes from the observation model (Poisson or binomial); when closed (v_t = 0) the count is a structural zero. The sampler stores v_t for each draw, so the structural-zero probability is

\Pr(\text{structural} \mid y_t = 0) = 1 - \overline{v_t},

the posterior mean of the gate being closed. Non-zero observations are always sampling observations and have structural probability 0.

Value

A data frame with columns time, observed, p_structural (posterior probability the zero is structural) and p_sampling (1 - p_structural).

Examples

sim <- simulate_dynamic_poisson(60, 0.2, 2, zero_inflation = 0.25, seed = 1)
fit <- fit_dynamic_model(sim$y, zero_inflation = TRUE, nsave = 300, nburn = 200,
                         seed = 1)
structural_zero_prob(fit)

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