Generating correlated random numbers

11 visualizzazioni (ultimi 30 giorni)
Stavros Zanos
Stavros Zanos il 22 Lug 2013
Modificato: krana il 29 Dic 2017
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.

Risposte (1)

krana
krana il 29 Dic 2017
Modificato: krana il 29 Dic 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

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by