Learn R Programming

MultiDiscreteRNG (version 0.1.0)

genNB: Generate multivariate negative binomial data

Description

This function is the engine for simulating correlated negative binomial outcomes once the intermediate binary parameters have been computed. It first generates correlated multivariate binary data using a latent normal approach implemented in generate.binaryVar and then maps the binary outcomes back to the original negative binomial scales via a reverse-collapsing step implemented in BinToNB, using the negative binomial probability mass function and dichotomization locations stored in binObj.

Usage

genNB(no.rows, binObj)

Value

A generated multivariate negative binomial dataset (returned as a list containing the simulated data matrix and its empirical correlation matrix).

Arguments

no.rows

integer; number of observations to generate (sample size \(N\)).

binObj

list; intermediate object produced by the binary-correlation calibration step for negative binomial margins (e.g., simBinaryCorr.NB). It must contain:

pvec

numeric vector of binary success probabilities \(p_j^b\).

intermat

intermediate/tetrachoric correlation matrix for the latent normal model used to generate correlated binary data.

NBprop

list of negative binomial PMFs (probability masses over the support) used in the reverse-collapsing step.

Mlocation

numeric vector of dichotomization thresholds (median locations) used to split each marginal distribution into binary categories.

Examples

Run this code
r.vec <- c(3, 5)
p.vec <- c(0.7, 0.5)

M<- c(0.2, 0.3)
N <- diag(2)
N[lower.tri(N)] <- M
cmat<- N + t(N)
diag(cmat) <- 1

# In real data simulation, no.rows should set to 100000 for accurate data generation
# in the intermediate step.
binObj = simBinaryCorr.NB(NB.r.vec = r.vec, NB.prob.vec = p.vec, CorrMat = cmat,
no.rows = 20000, steps= 0.025)

data = genNB(no.rows = 100, binObj = binObj)$y

Run the code above in your browser using DataLab