/* Plackett Copula */ /* C(u,v)=((1+(theta-1)*(u+v))-sqrt((1+(theta-1)*(u+v))^2-4*theta*(theta-1)*(u.*v)))/(2*(theta-1)) */ /* Solve q=1/2-1/(4*(theta-1))*((1+(theta-1)*(u+v))^2-4*theta*(theta-1)*(u.*v))^(-1/2) */ /* .*(2*(1+(theta-1)*(u+v))*(theta-1)-4*theta*(theta-1)*v); (=Cu) */ /* in terms of v numerically. */ new; cls; theta=2; n=1000; U=Cpla(theta,n); library pgraph; graphset; _plctrl=-1; xy(U[.,1],U[.,2]); proc Cpla(theta,n); local u,q,v; if theta<=0; errorlog "ERROR: Parameter theta must be positive."; retp("."); endif; u=rndu(n,1); q=rndu(n,1); v=calcv(u,q,theta); 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)=1/2-1/(4*(theta-1))*((1+(theta-1)*(u+v))^2-4*theta*(theta-1)*(u.*v))^(-1/2) .*(2*(1+(theta-1)*(u+v))*(theta-1)-4*theta*(theta-1)*v);