# Generating correlated samples from bernoulli variables [duplicate]

I am trying to implement a program that samples from two identically distributed Bernoulli random variables, $$X_1$$ and $$X_2$$, such that they have a specific correlation coefficient, $$\rho$$.

I found a post that almost does what I want to do:

https://stats.stackexchange.com/a/318935

However, the parameter $$p$$ of the Bernoulli distributions is dependent on $$\rho$$, i.e., I can't leave $$p$$ fixed and generate samples with a desired $$\rho$$. In theory, I do not see any reason why this should not be possible.

• Because the thread you reference thoroughly answers this question, please provide more explanation of what you are looking for.
– whuber
Oct 23, 2020 at 18:55
• I'm not sure what is missing in my explanation (last sentence). What is not clear, exactly? I'm looking for generating the samples by choosing both $\rho$ and $p$ not only one or the other. Oct 23, 2020 at 19:37
• Your question has already been completely answered. I can't understand your last paragraph because it's not grammatical: the English syntax doesn't make sense. I am beginning to wonder whether the thread at stats.stackexchange.com/questions/284996 might instead be what you're looking for.
– whuber
Oct 23, 2020 at 20:03
• I fixed the typo in the last sentence. Maybe there's something I'm missing.. isn't it possible to ask for a method to generate samples from two bernoullis for a given $\rho$ and $p$? The answer I linked to in my post and that you say it answers my question doesn't let you do that, it only allows it if either $\rho$ or $p$ is fixed but not for any arbitrary pair... Oct 23, 2020 at 20:48
• Oh, I see what you mean. I think you're right, @whuber, the one you referenced does solve this question. I missed it. Thanks! Oct 23, 2020 at 22:12