Learn R Programming

MultiDiscreteRNG (version 0.1.0)

genB: Generate multivariate binomial data

Description

This function is the engine for simulating correlated 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 binomial scales via a reverse-collapsing step implemented in BinToB, using the binomial probability mass function and dichotomization locations stored in binObj

Usage

genB(no.rows, binObj)

Value

A generated multivariate 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 binomial margins (e.g., simBinaryCorr.B). 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.

BProp

list of 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
n.vec <- c(3, 4)
p.vec <- c(0.5, 0.5)

M<- c(0.3, 0.4)
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.B(B.n.vec = n.vec, B.prob.vec = p.vec,
CorrMat = cmat, no.rows = 20000, steps= 0.025)

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

Run the code above in your browser using DataLab