/* Mixed Copula in Extreme Value Family */ /* C(u,v)=u.*v.*exp(-theta*(ln(u).*ln(v))./ln(u.*v)) */ /* Solve q=v.*exp(-theta*(ln(u).*ln(v))./ln(u.*v)) */ /* +u.*v.*exp(-theta*(ln(u).*ln(v))./ln(u.*v)) */ /* .*( (-theta*ln(v)./u.*ln(u.*v)+theta/u.*ln(u).*ln(v))./(ln(u.*v))^2 ) (=Cu) */ /* in terms of v numerically. This is very slow. */ new; cls; theta=0.9; n=1000; U=Cmix(theta,n); library pgraph; graphset; _plctrl=-1; xy(U[.,1],U[.,2]); proc Cmix(theta,n); local u,q,v; if theta<0 or theta>1; errorlog "ERROR: Parameter theta must be 0<=theta<=1"; 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)=v.*exp(-theta*(ln(u).*ln(v))./ln(u.*v)) +u.*v.*exp(-theta*(ln(u).*ln(v))./ln(u.*v)) .*( (-theta*ln(v)./u.*ln(u.*v)+theta/u.*ln(u).*ln(v))./(ln(u.*v))^2 );