Consider we have 4 vectors, V1,V2,nf1 and nf2. We need to generate n=8736 random numbers that each pair of (V1,V2) , (V1,nf1), (V2,nf2) and (nf1,nf2) to be correlate as follow:
Rvv=0.6 for (V1,V2)
Rvn=0.5 for (V1,nf1) and (V2,nf2)
Rnn=0 for (nf1,nf2)
(It's not important what correlation of (V1,nf2) and (V2, nf1) is). Now we use copula to generate correlated random numbers in MATLAB:
Rvv=0.6;
Rvn=0.5;
Rnn=0;
n = 8736;
%V1 V2 nf1 nf2
Rho = [1 Rvv Rvn 0 ; %V1
Rvv 1 0 Rvn; %V2
Rvn 0 1 Rnn; %nf1
0 Rvn Rnn 1 ]; %nf2
Random_no = copularnd('Gaussian',Rho,n);
It's all OK when Rvv is 0.6, and Random_no will be a 8736 by 4 matrix, that each pair of columns are correlated as we specified by Rho Matrix. BUT when Rvv=0.9, MATLAB returns error as follow:
Error using mvnrnd
SIGMA must be a symmetric positive semi-definite matrix.
Error in copularnd
u = normcdf(mvnrnd(zeros(1,d),Rho,n));
I can't understand what the problem is and how can I really generate correlated random numbers using copula. I'll really appreciate if anyone can help me through this problem.
Aucun commentaire:
Enregistrer un commentaire