Learn R Programming

oneinfl (version 1.0.2)

roiztnb: Generate Random Counts from a One-Inflated Zero-Truncated Negative Binomial Process

Description

Simulates count data from a one-inflated, zero-truncated negative binomial (OIZTNB) process using specified parameters for the rate, one-inflation, and dispersion components.

Usage

roiztnb(b, g, alpha, X, Z)

Value

A numeric vector of simulated count data.

Arguments

b

A numeric vector of coefficients for the rate component.

g

A numeric vector of coefficients for the one-inflation component.

alpha

A numeric value representing the dispersion parameter for the negative binomial distribution.

X

A matrix or data frame of predictor variables for the rate component.

Z

A matrix or data frame of predictor variables for the one-inflation component.

Details

This function generates count data from a one-inflated, zero-truncated negative binomial process. The process combines:

  • A negative binomial distribution for counts greater than one.

  • A one-inflation component that adjusts the probability of observing a count of one.

The algorithm:

  1. Calculates the rate parameter (\(\lambda\)) as \(\exp(X \cdot b)\).

  2. Computes the one-inflation probabilities (\(\omega\)) based on \(Z \cdot g\).

  3. Computes the negative binomial dispersion parameter (\(\theta = \lambda / \alpha\)).

  4. Simulates counts for each observation:

    • Draws a random number to determine whether the count is one.

    • Iteratively calculates probabilities for higher counts until the random number is matched.

This function is useful for generating synthetic data for testing or simulation studies involving one-inflated, zero-truncated negative binomial models.

See Also

oneinfl for fitting one-inflated models.

Examples

Run this code
# Example usage
set.seed(123)
X <- matrix(rnorm(100), ncol = 2)
Z <- matrix(rnorm(100), ncol = 2)
b <- c(0.5, -0.2)
g <- c(1.0, 0.3)
alpha <- 1.5
simulated_data <- roiztnb(b, g, alpha, X, Z)
print(simulated_data)

Run the code above in your browser using DataLab