Generating correlated random numbers
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have 2 independent variables X={x1,x2,...,xn} and Y={y1,y2,...,yn}.
I want to generate a random dependent variable Z={z1,z2,...,zn} that will bear a correlation coefficient Czx with X and Czy with Y.
I found the way to do this for one independent variable X that takes values between 0 and 1:
Z = Czx * rand(n,1) + sqrt(1-Czx^2)*X
It's not clear to me how to do that for two independent variables that both are correlated to Z and can take values from different ranges (e.g. 0<X<1 and 1<Y<10).
Any help will be appreciated.
0 Kommentare
Antworten (1)
krana
am 29 Dez. 2017
Bearbeitet: krana
am 29 Dez. 2017
I guess I'm a little late here but perhaps some other people might find this response useful. I created this simple function that I used as a workaround.
% code
function [Zv Zs]= randomcorrelatednum(rho)
Zv= rand(1);
Zs = rho*Zv + sqrt(1-rho^2)*rand(1);
while Zv> 1.00000001
Zv= rand(1);
Zs = rho*Zv + sqrt(1-rho^2)*rand(1);
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!