corrBern | R Documentation |
Generate Bernoulli random vector with a certain correlation matrix
corrBern(n, probs, Rho)
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). |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.