Re: Generating a Matrix of Random values with a specified Correlation
- From: willgarrison@xxxxxxxxx
- Date: Thu, 25 Sep 2008 11:30:06 -0700 (PDT)
On Sep 25, 12:17 pm, Robert Israel
<isr...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
willgarri...@xxxxxxxxx writes:
I'm trying to generate two columns of random values where each value
is between 1 and 5 where the matrix as a whole has a specified
correlation.
Ideally this is what I'm looking for:
Example algorithm:
1. Generate 20 random values between 1 and 5 in array A.
2. Generate 20 random values between 1 and 5 in array B.
3. Create a 3rd array (array C), where array B is sorted so that array
A and array C have a correlation of X.
Does anyone have any ideas on how to do this?
This may be a horrible way to solve this problem. If so, does anyone
have any ideas on how else I could go about it?
Start with your two arrays A and B. Let a=Var(A), b=Var(B), c=Cov(A,B),
so the (Pearson) correlation of A and B is rho = c/sqrt(a b). Let's
suppose the desired correlation x > rho (where of course x <= 1).
Consider C = tA + (1-t)B, where 0 <= t <= 1.
We have Cov(A,C) = ta + (1-t) c and
Var(C) = t^2 a + 2 t (1-t) c + (1-t)^2 b so the correlation of A and C
is (ta + (1-t)c)/sqrt(a(t^2 a + 2t(1-t)c + (1-t)^2 b)).
Set this equal to x and solve for t: there should be exactly one solution
in the interval 0 <= t <= 1.
On the other hand, if -1 <= x < rho,
try C = t R + (1-t) B where each R_j = 6 - A_j.
--
Robert Israel isr...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia Vancouver, BC, Canada
Thank you Robert.
I think this is not only over my head but perhaps not the exact answer
I'm looking for. However, it being over my head, it's impossible for
me to know.
Let me phrase this as a simpler question with hopes of improving my
chances of understanding your response.
Let say I have some number, A, that is in the range of 1 to 5. I need
to generate another number B, also in the range of 1 to 5 where the
two numbers, A and B, have a correlation of X.
Is this even possible, or is the calculation of correlation a one way
street, meaning that I can only calculate the correlation of a data
set as opposed to generate a data set based on a predefined
correlation?
I apologize again if you already answered this question in your
previous reply and just went too over my head for me to understand.
.
- Follow-Ups:
- Re: Generating a Matrix of Random values with a specified Correlation
- From: James Waldby
- Re: Generating a Matrix of Random values with a specified Correlation
- References:
- Generating a Matrix of Random values with a specified Correlation
- From: willgarrison
- Re: Generating a Matrix of Random values with a specified Correlation
- From: Robert Israel
- Generating a Matrix of Random values with a specified Correlation
- Prev by Date: Re: smallest prime number greater than n
- Next by Date: Re: help showing something is the infimim of a set
- Previous by thread: Re: Generating a Matrix of Random values with a specified Correlation
- Next by thread: Re: Generating a Matrix of Random values with a specified Correlation
- Index(es):
Relevant Pages
|