Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
generating correlated vectors

Subject: generating correlated vectors

From: Mel

Date: 16 Mar, 2010 20:12:22

Message: 1 of 3

I have two vectors (A and B) that are correlated @ 0.2510, n=59 for each, different means and variances. I would like to generate a random vector with the mean and variance equal to that of B while maintaining the 0.2510 correlation with A. Any ideas would be greatly appreciated.

Thanks,
Mel

Subject: generating correlated vectors

From: Roger Stafford

Date: 16 Mar, 2010 22:57:05

Message: 2 of 3

"Mel " <melkunkel@u.boisestate.edu> wrote in message <hnoon6$kv5$1@fred.mathworks.com>...
> I have two vectors (A and B) that are correlated @ 0.2510, n=59 for each, different means and variances. I would like to generate a random vector with the mean and variance equal to that of B while maintaining the 0.2510 correlation with A. Any ideas would be greatly appreciated.
>
> Thanks,
> Mel

  You haven't specified the nature of distribution your random variable is to have. Let us suppose you make it a linear combination of A and a standard normal random variable R = randn(n,1) with coefficients to be determined so as to make your requirements come true. First calculate:

 mA = mean(A); vA = var(A); % Get means and variances of A & B
 mB = mean(B); vB = var(B);
 T = corrcoef(A,B); cAB = T(1,2); % Correlation between A & B
 R = randn(n,1); % Standard normal distribution

  Now let the random variable be defined as C = K1 + K2*A + K3*R and adjust coefficients K1, K2, and K3 so that the following three conditions are satified:

 1) The expected value of mean(C) equals mB
 2) The expected value of variance(C) equals vB
 3) The expected value of the correlation between A & C equals cAB

This will give you three equations in K1, K2, and K3 so that they can be determined. Then C will have the desired properties that you seek.

  I'll obtain the easiest equation and leave the other harder ones and their solution to you. ;-) The first equation would be:

 E{mean(C)} = E{mean(K1+K2*A+K3*R)} = K1 + K2*mA + K3*E{mean(R)}
 = K1 + K2*mA = mB

where E{-} means expected value. This last equality gives you the first requirement in 1) above.

  For the second equation I get K2^2*vA + K3^2 = vB, but I'll let you figure out how that is derived. For the third equation, you are entirely on your own.

  Note that if C is to be a valid random variable, the best you can do is to require that the expected value of its mean, variance, and correlation be the desired values. To force it to have these values exactly would remove it from the domain of true random variables.

Roger Stafford

Subject: generating correlated vectors

From: Mel

Date: 17 Mar, 2010 11:50:23

Message: 3 of 3

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hnp2c1$dec$1@fred.mathworks.com>...
> "Mel " <melkunkel@u.boisestate.edu> wrote in message <hnoon6$kv5$1@fred.mathworks.com>...
> > I have two vectors (A and B) that are correlated @ 0.2510, n=59 for each, different means and variances. I would like to generate a random vector with the mean and variance equal to that of B while maintaining the 0.2510 correlation with A. Any ideas would be greatly appreciated.
> >
> > Thanks,
> > Mel
>
> You haven't specified the nature of distribution your random variable is to have. Let us suppose you make it a linear combination of A and a standard normal random variable R = randn(n,1) with coefficients to be determined so as to make your requirements come true. First calculate:
>
> mA = mean(A); vA = var(A); % Get means and variances of A & B
> mB = mean(B); vB = var(B);
> T = corrcoef(A,B); cAB = T(1,2); % Correlation between A & B
> R = randn(n,1); % Standard normal distribution
>
> Now let the random variable be defined as C = K1 + K2*A + K3*R and adjust coefficients K1, K2, and K3 so that the following three conditions are satified:
>
> 1) The expected value of mean(C) equals mB
> 2) The expected value of variance(C) equals vB
> 3) The expected value of the correlation between A & C equals cAB
>
> This will give you three equations in K1, K2, and K3 so that they can be determined. Then C will have the desired properties that you seek.
>
> I'll obtain the easiest equation and leave the other harder ones and their solution to you. ;-) The first equation would be:
>
> E{mean(C)} = E{mean(K1+K2*A+K3*R)} = K1 + K2*mA + K3*E{mean(R)}
> = K1 + K2*mA = mB
>
> where E{-} means expected value. This last equality gives you the first requirement in 1) above.
>
> For the second equation I get K2^2*vA + K3^2 = vB, but I'll let you figure out how that is derived. For the third equation, you are entirely on your own.
>
> Note that if C is to be a valid random variable, the best you can do is to require that the expected value of its mean, variance, and correlation be the desired values. To force it to have these values exactly would remove it from the domain of true random variables.
>
> Roger Stafford

Thanks Roger,

I'll give your approach a try and see how it goes.

Mel

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us