Learn R Programming

MultiDiscreteRNG (version 0.1.0)

BinToB: Convert multivariate binary data back to the original binomial scale

Description

This function maps multivariate binary data to multivariate binomial outcomes, preserving the original marginal distribution characteristics. Given the binary representation of the data, the function assigns binomial values based on the original probability mass functions and the location of the median split.

Usage

BinToB(prop.vec.bin, BProp, Mlocation, bin.data)

Value

A list containing the multivariate binomial data and its correlation matrix

Arguments

prop.vec.bin

A vector of binary probabilities

BProp

Binary proportion

Mlocation

Indices of the medians in the vector

bin.data

Generated multivariate binary data.

Examples

Run this code
# Generate binary probabilities and probability mass functions for 3 variables
B.n.vec <- c(3, 4, 5)
B.prob.vec <- c(0.5, 0.5, 0.5)
p <- calc.bin.prob.B(B.n.vec, B.prob.vec)
pvec <- p$p
prop <- p$prop
Mlocation <- p$Mlocation

# Select the first two variables for demonstration
pvec.pair      <- pvec[1:2]
Mlocation.pair <- Mlocation[1:2]
prop.pair      <- list(prop[[1]], prop[[2]])

# Specify a target correlation matrix for two binary variables
del.next <- matrix(c(1.0, 0.3,
                     0.3, 1.0),
                   nrow = 2, byrow = TRUE)

# Simulate N = 100 binary observations with the desired correlation
inter_bin <- generate.binaryVar(100, pvec.pair, del.next)

# Convert back to binomial scale
Mydata <- BinToB(pvec.pair, prop.pair, Mlocation.pair, inter_bin)

Run the code above in your browser using DataLab