Gaussian Copula and Correlation, I am trying to find gaussian copula for multiple variable, Please help me, is the u which i underline is correct or not
3 views (last 30 days)
Show older comments
N = 1000;
norm_mean = 0;
norm_var = 1;
r1= norm_mean+sqrt(norm_var)*randn(1,N);
%calculating PDF
y1 = pdf('Normal',r1,norm_mean,sqrt(norm_var));
%Random variable 2
r2= norm_mean+sqrt(norm_var)*randn(1,N);
y2 = pdf('Normal',r2,norm_mean,sqrt(norm_var));
%Random Variable 3
r3= norm_mean+sqrt(norm_var)*randn(1,N);
y3 = pdf('Normal',r3,norm_mean,sqrt(norm_var));
%Calculate correlation between columns Y1 and Y2
[rho,pval] = corr(y1(:),y2(:),'type','Spearman')
[rho1,pval1] = corr(y2(:),y3(:),'type','Spearman')
[rho2,pval2] = corr(y3(:),y1(:),'type','Spearman')
%Calculating correlation between Y1 and Y2 using corrcoef
[r,p] = corrcoef(y1(:),y2(:))
r2 = copulastat('Gaussian',rho) %check
%calculating Gaussian/Normal copula
u = copularnd('Gaussian',rho,N) +copularnd('Gaussian',rho1,N)+copularnd('Gaussian',rho2,N)
%short the numbers
[s1,i1] = sort(u(:,1));
[s2,i2] = sort(u(:,2));
% two vectors of zeros, x1 and x2, that are the same size as the sorted copula vectors
x1 = zeros(size(s1));
x2 = zeros(size(s2));
x1(i1) = sort(y1);
x2(i2) = sort(y2);
b = [betainv(u(:,1),1,2), betainv(u(:,2),1.5,2)];
figure
scatterhist(b(:,1),b(:,2))
tau_sample = corr(b,'type','Spearman')
0 Comments
Answers (0)
See Also
Categories
Find more on Copula Distributions and Correlated Samples in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!