Learn R Programming

MultiDiscreteRNG (version 0.1.0)

simBinaryCorr.NB: Compute intermediate binary correlations for multivariate negative binomial data

Description

This function implements Step 2 of the algorithm to calibrate the intermediate latent-normal correlation matrix used to generate correlated binary variables for negative binomial margins. For each pair of variables, it iteratively updates the latent correlation so that, after (i) generating correlated binary data via generate.binaryVar and (ii) mapping back to negative binomial outcomes via BinToNB, the empirical correlation of the resulting NB pair matches the user-specified target correlation in CorrMat. The calibrated pairwise latent correlations are then assembled into a full intermediate matrix, which is adjusted to be positive definite if needed.

Usage

simBinaryCorr.NB(NB.r.vec, NB.prob.vec, CorrMat, no.rows, steps = 0.025)

Value

intermediate multivariate binary Correlation matrix

Arguments

NB.r.vec

vector of number of trials

NB.prob.vec

vector of probabilities

CorrMat

specified correlation matrix

no.rows

number of observations for generating multivariate binary data

steps

fraction of difference between the current and target matrix to be added in each iteration.

Examples

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

M<- c(0.45, 0.45)
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)

Run the code above in your browser using DataLab