RE: [R] Generating a binomial random variable correlated with a

From: Ashraf Chaudhary <mchaudha_at_jhsph.edu>
Date: Sun 17 Apr 2005 - 06:46:07 EST


Ted:
Thank you for your help. All I want is a binomial random variable that is correlated with a normal random variable with specified correlation. By linear I mean the ordinary Pearson correlation. I tried the following two methods, in each case the resulting correlation is substantially less than the one specified.

Method I: Generate two correlated normals (using Cholesky decomposition method) and dichotomize one (0/1) to get the binomial. Method II: Generate two correlated variables, one binomial and one normal using the Cholesky decomposition methods.

Here is how I did:

X <- rnorm(100)          
Y <- rnorm(100)           
r<- 0.7
Y1 <- X*r+Y*sqrt(1-r**2)     
cor(X,Y1)	    # Correlated normals using Cholesky decomposition
cor(X>0.84,Y1) # Method I

##
X1 <- rbinom(100,1,0.5)
Y2 <- X1*r+Y*sqrt(1-r**2)

cor(X1,Y2); # Method II

I would like to thank Ben from whom I received the following response:

"Are you computing the correlation between the continuous variable and the dichotomized variable with the formula for the biserial correlation? If not, that is probably the root of your problem."

I looked at the biserial correlation which is a special case of Pearson correlation between a continuous and binomial random variable. I don't know how I can use it to generate the data. Any idea?

Regards,
Ashraf       

-----Original Message-----
From: Ted Harding [mailto:Ted.Harding@nessie.mcc.ac.uk] Sent: Saturday, April 16, 2005 3:22 AM
To: Ashraf Chaudhary
Cc: r-help@stat.math.ethz.ch
Subject: RE: [R] Generating a binomial random variable correlated with a

On 15-Apr-05 Ashraf Chaudhary wrote:
> Hi,
> I am posting this problem again (with some additional detail)
> as I am stuck and could not get it resolved as yet. I tried to
> look up in alternative sources but with no success. Here it is:
>
> I need to generate a binomial (binary 0/1) random variable linearly
> correlated with a normal random variable with a specified correlation.
> Off course, the correlation coefficient would not be same at each run
> because of randomness.
>
> If I generate two correlated normals with specified correlation and
> dichotomize one, the correlation of a normal and the binomial random
> variable would not be the same as specified.
>
> I greatly appreciate your help.
> Ashraf

Hello Ashraf,

I do not know what you mean by "a binomial random variable linearly correlated with a normal random variable." You can certainly (and indeed your dichotomy method is one way) generate a binomial and a normal which are correlated. But apparently this gives a result which is "not the same as specified": however, I cannot see in your description a specification which would violated by the result of doing so.

You cannot expect a binomial variable to be such that, for instance, its expectation conditional on the value of a normal variable would be a linear function of the normal variable, since this would allow a situation where the expectation was greater than 1 or less than 0. But I wonder what else you could possibly mean by "linearly correlated".

Please therefore be more explicit about the specification of your problem!

Trying to help,
Ted.



E-Mail: (Ted Harding) <Ted.Harding@nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861
Date: 16-Apr-05                                       Time: 08:21:42
------------------------------ XFMail ------------------------------

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Apr 17 06:54:48 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:13 EST