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