/* Cubic Copula C(u,v)=u.*v+theta*(u.*(u-1).*(2*u-1)).*(v.*(v-1).*(2*v-1)) */ /* Solve q=v+theta.*(v.*(v-1).*(2*v-1)).*(6*u^2-6*u+1) (=Cu) */ /* in terms of v numerically. */ new; cls; theta=1.5; n=1000; U=Ccb(theta,n); library pgraph; graphset; _plctrl=-1; xy(U[.,1],U[.,2]); proc Ccb(theta,n); local u,q,v; if theta<-1 or theta>2; errorlog "ERROR: Parameter theta must be -1<=theta<=2."; retp("."); endif; u=rndu(n,1); q=rndu(n,1); if theta==0; v=q; else; v=calcv(u,q,theta); endif; retp(u~v); endp; proc calcv(u,q,theta); local vstar,vstarstar,i,v,x; vstar=zeros(rows(q),1); i=1; do while i<=rows(q); v=seqa(0.0001,0.0001,10000); x=abs(q[i]-Cu(u[i],v,theta)); vstar[i]=v[minindc(x)]; v=seqa(vstar[i]-0.00005,0.00000001,10000); x=abs(q[i]-Cu(u[i],v,theta)); vstarstar=v[minindc(x)]; if vstarstar==vstar[i]-0.00005; v=seqa(0.00000001,0.00000001,10000); x=abs(q[i]-Cu(u[i],v,theta)); vstar[i]=v[minindc(x)]; else; vstar[i]=vstarstar; endif; if vstarstar>1; vstar[i]=1; endif; i=i+1; endo; retp(vstar); endp; fn Cu(u,v,theta)=v+theta.*(v.*(v-1).*(2*v-1)).*(6*u^2-6*u+1);