/* Plackett Copula (by acceptance-rejection method) */ /* cdf: C(u,v)=((1+(theta-1)*(u+v))-sqrt((1+(theta-1)*(u+v))^2-4*theta*(theta-1)*(u.*v)))/(2*(theta-1)) */ /* Notice: This simulation is rough. */ new; cls; theta=0.1; n=1000; X=Cplack(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("Plackett Copula"); _plctrl=-1; xy(X[.,1],X[.,2]); proc Cplack(theta,n); local u,v,c,h,i,us,vs,x,z; if theta<=0; errorlog "ERROR: Parameter theta must be positive."; 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( theta.*((1+((theta-1)).*(u+v))-2*(theta-1).*u.*v)./(((1+((theta-1)).*(u+v))^2-4*theta.*(theta-1).*u.*v)^(3/2)) ); endp;