# [R] generating correlated Bernoulli random variables

Rolf Turner r.turner at auckland.ac.nz
Tue Jul 3 03:58:08 CEST 2007

On 3/07/2007, at 1:28 PM, Vineet Kumar wrote:

> Hi all,
> I was wondering how to generate samples for two RVs X1 and X2.
>
> X1 ~ Bernoulli (p1)
> X2 ~ Bernoulli (p2)
>
> Also, X1 and X2 are correlated with correlation \rho.

Back-of-envelope calculation, not checked, not tested:

Let q1 = p2 + (rho/p1) * sqrt((1-p1)*(1-p2))

q2 = (p2 - q1*p1)/(1-p1)

Generate X1 with success probability p1.
If X1 = 1, generate X2 with probability q1, else generate X2 with
probability q2.

Clearly there must be restrictions on the value of rho (in terms of
p1 and p2) in
order that the values of q1 and q2 lie between 0 and 1.

I.e. for some values of rho your goal will be impossible to achieve.

cheers,

Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confidenti...{{dropped}}