corrBern: Generate Bernoulli random vector with a certain correlation...

View source: R/misc.R

corrBernR Documentation

Generate Bernoulli random vector with a certain correlation matrix

Description

Generate Bernoulli random vector with a certain correlation matrix

Usage

corrBern(n, probs, Rho)

Arguments

n

the desired number of Bernoulli random vectors to generate

probs

the marginal probabilities of success for the Bernoulli random variables

Rho

the desired correlation matrix (error will occur if the correlation matrix is inadmissable).

Value

a matrix of which the rows are the Bernoulli random vectors

This function implements the method from Chul Gyu Park, Taesung Park and Dong Wan Shin, A Simple Method for Generating Correlated Binary Variates The American Statistician, Vol. 50, No. 4 (Nov., 1996), pp. 306-310, for generating correlated Bernoulli random variables.

Examples

p <- 6 # number of Bernoulli random variables
Rho <- .2^abs(outer(1:p,1:p,"-"))  # matrix of desired correlations (must all be non-negative!)
probs <- 1:p/(2*p) # vector of marginal probabilities
n <- 500 # the number of independent realizations of the Bernoulli random vector

Z <- corrBern(n,probs,Rho)

Rho
cor(Z)

gregorkb/semipadd2pop documentation built on Oct. 2, 2022, 1:37 p.m.