/* Frank Copula in Archimedean Family ( phi(u)=-ln((exp(-theta*u)-1)/(exp(-theta)-1)) ) */ new; cls; theta=-5; n=1000; U=Cfrank(theta,n); library pgraph; graphset; _plctrl=-1; xy(U[.,1],U[.,2]); proc Cfrank(theta,n); local s,q,t,u,v; if theta==0; errorlog "ERROR: Parameter theta must be nonzero."; retp("."); endif; s=rndu(n,1); q=rndu(n,1); t=calct(q,theta); u=phi_1(s.*phi(t,theta),theta); v=phi_1((1-s).*phi(t,theta),theta); retp(u~v); endp; proc calct(q,theta); local tstar,tstarstar,i,t,x; tstar=zeros(rows(q),1); i=1; do while i<=rows(q); t=seqa(0.0001,0.0001,10000); x=abs(q[i]-(t-phi(t,theta)./phi1(t,theta))); tstar[i]=t[minindc(x)]; t=seqa(tstar[i]-0.00005,0.00000001,10000); x=abs(q[i]-(t-phi(t,theta)./phi1(t,theta))); tstarstar=t[minindc(x)]; if tstarstar==tstar[i]-0.00005; t=seqa(0.00000001,0.00000001,10000); x=abs(q[i]-(t-phi(t,theta)./phi1(t,theta))); tstar[i]=t[minindc(x)]; else; tstar[i]=tstarstar; endif; if tstarstar>1; tstar[i]=1; endif; i=i+1; endo; retp(tstar); endp; fn phi(u,theta)=-ln((exp(-theta*u)-1)/(exp(-theta)-1)); fn phi1(u,theta)=theta*exp(-theta*u)./(exp(-theta*u)-1); fn phi_1(u,theta)=-1/theta*ln(exp(-u-theta)-exp(-u)+1);