/* Gumbel-Barnett Copula (by acceptance-rejection method) */ /* cdf: C(u,v)=u.*v.*exp(-theta*(-ln(u)).*(-ln(v))) */ /* Notice: This simulation is rough. */ new; cls; theta=1; n=1000; X=Cgb(theta,n); library pgraph; graphset; pqgwin auto; u=seqa(0.01,0.01,99); v=seqa(0.01,0.01,99); title("target density"); xlabel("u"); ylabel("v"); contour(u',v,pdf(u,v',theta)); surface(u',v,pdf(u,v',theta)); title("Gumbel-Barnett Copula"); _plctrl=-1; xy(X[.,1],X[.,2]); proc Cgb(theta,n); local u,v,c,h,i,us,vs,x,z; if theta<0 or theta>1; errorlog "ERROR: Parameter theta must be 0<=theta<=1."; retp("."); endif; u=seqa(0.01,0.01,100); v=seqa(0.01,0.01,100); c=pdf(u',v,theta); h=maxc(maxc(c)); u=zeros(n,1); v=zeros(n,1); i=1; do while i<=n; label: us=rndu(1,1); vs=rndu(1,1); x=rndu(1,1); z=pdf(us,vs,theta); if x<=(z/h); u[i]=us; v[i]=vs; else; goto label; endif; i=i+1; endo; retp(u~v); endp; proc pdf(u,v,theta); retp( (1-theta-theta*(ln(u)+ln(v))+theta^2*ln(u).*ln(v)).*exp(-theta*ln(u).*ln(v)) ); endp;