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

Generating a string of random standard normal variables that are correlated

Asked by Natialol on 6 Dec 2011

Hi Everyone,

I'm a sort of newbie, I would like to know how and what the implications are of 'Generating a string of random standard normal variables that are correlated with each other'.

To get by this problem, I have been generating and correlating my desired sequence to a different random variable and then calculating the correlation between my sequence.

Thanks for the anticipated answer.

ps: Generate random standard normal's A, B, C, D so that have a correlation and standard deviation of corr and std.

Thanks again

0 Comments

Natialol

Products

No products are associated with this question.

2 Answers

Answer by Daniel on 6 Dec 2011
Accepted answer

I am not sure if this is homework or not ...

Start off with two independent random variables with zero mean and standard deviation sigma.

sigma  = 10;
X = sigma*randn(1e7, 1);
Y = sigma*randn(1e7, 1);

Then make two new random variables from these with correlation rho.

rho = 0.2;
A = X;
B = sqrt(rho^2)*X+sqrt(1-rho^2)*Y;
[std(A), std(B)]
corrcoef(A, B)

When you add a third random variable C you need to specify what you want rho_AB, rho_AC, and rho_AB to be. The basic idea is the same: start with N independent random variables and add them together with appropriate weighting to get N new random variables.

2 Comments

Natialol on 6 Dec 2011

Thanks Daniel,

It's not an homework. I think i was unclear.

[1] I am not looking at correlating a simple randn(n, 1) to another such string. I am looking to generate a single string of random standard variables say [5X1] so that the five variables are all correlated to each other with a correlation corr and standard deviation. Sorry if my initial post was misleading.

[2] On the solution you, I will like to ask if the each corresponding element in the resulting A and B are correlated to each other. Is each element [jX1] of A correlated to the same element [jX1] of B with correlation rho?

Thanks

Daniel on 6 Dec 2011

I am very lost. It is odd to talk about the correlation between scalars like A_i and B_j. I think what you are asking is to create 5 random processes which have a particular covariance and then you want 1 value from each process. My answer provides 2 random processes which each have 1e7 values. If you extend it to 5 terms (A,B,C,D,E) then you can do a = A(i), b = B(j), c = C(k) ... and I think what you want is [a,b,c,d,e]. Of course if you only want 1 value, you do not need to generate 1e7 values.

Daniel
Answer by Oleg Komarov on 6 Dec 2011

Given a correlation matrix C = A*A', then A = P*sqrt(D), where:

[P,D] = eig(C);  % spectral decomposition

To get the correlated normal random series Z, use W = (W1, ...,W2)' (the normal random series):

Z = A*W;

Note that if you have 4 variables, then C is 4 by 4, and W should be 4 by nobs.

1 Comment

Natialol on 6 Dec 2011

I'm trying to read up on the answer and will accept as soon as I understand that it does the above. Please can you also comment on the above question to Daniel?

Oleg Komarov

Contact us