Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: generating correlated vectors Date: Tue, 16 Mar 2010 22:57:05 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 33 Message-ID: <hnp2c1$dec$1@fred.mathworks.com> References: <hnoon6$kv5$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1268780225 13772 172.30.248.37 (16 Mar 2010 22:57:05 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 16 Mar 2010 22:57:05 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:617416 "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