function bivprb ( h, k, r ) c*********************************************************************72 c cc BIVPRB computes a bivariate normal CDF for correlated X and Y. c c Discussion: c c This routine computes P( H < X, K < Y ) for X and Y standard normal c variables with correlation R. c c Modified: c c 31 January 2008 c c Author: c c Original version by Mike Patefield, David Tandy. c Modifications by John Burkardt. c c Reference: c c Mike Patefield, David Tandy, c Fast and Accurate Calculation of Owen's T Function, c Journal of Statistical Software, c Volume 5, Number 5, 2000, pages 1-25. c c Parameters: c c Input, double precision H, K, the lower limits for X and Y. c 0 <= H, 0 <= K. c c Input, double precision R, the correlation between X and Y. c c Output, double precision BIVPRB, the requested probability. c implicit none double precision bivprb double precision h integer ifail double precision k double precision q double precision r double precision ri double precision rr double precision rroot2 parameter ( rroot2 = 0.70710678118654752440D+00 ) double precision rtwopi parameter ( rtwopi = 0.15915494309189533577D+00 ) double precision znorm2 if ( r .eq. 0.0D+00 ) then bivprb = znorm2 ( h ) * znorm2 ( k ) else rr = 1.0D+00 - r * r if ( 0.0D+00 .lt. rr ) then ri = 1.0D+00 / sqrt ( rr ) if ( 0.0D+00 .lt. h .and. 0.0D+00 .lt. k ) then bivprb = q ( h, ( k / h - r ) * ri ) & + q ( k, ( h / k - r ) * ri ) else if ( 0.0D+00 .lt. h ) then bivprb = q ( h, - r * ri ) else if ( 0.0D+00 .lt. k ) then bivprb = q ( k, - r * ri ) else bivprb = 0.25D+00 + rtwopi * asin ( r ) end if else if ( 1.0D+00 .le. r ) then if ( k .le. h ) then bivprb = znorm2 ( h ) else bivprb = znorm2 ( k ) end if else bivprb = 0.0D+00 end if end if return end subroutine normp ( z, p, q, pdf ) c*********************************************************************72 c cc NORMP computes the cumulative density of the standard normal distribution. c c Discussion: c c This is algorithm 5666 from Hart, et al. c c Modified: c c 27 March 1999 c c Author: c c Alan Miller c Modifications by John Burkardt. c c Reference: c c John Hart, Ward Cheney, Charles Lawson, Hans Maehly, c Charles Mesztenyi, John Rice, Henry Thacher, c Christoph Witzgall, c Computer Approximations, c Wiley, 1968, c LC: QA297.C64. c c Parameters: c c Input, double precision Z, divides the real line into two semi-infinite c intervals, over each of which the standard normal distribution c is to be integrated. c c Output, double precision P, Q, the integrals of the standard normal c distribution over the intervals ( - Infinity, Z] and c [Z, + Infinity ), respectively. c c Output, double precision PDF, the value of the standard normal c distribution at Z. c implicit none double precision cutoff parameter ( cutoff = 7.071D+00 ) double precision expntl double precision p double precision p0 parameter ( p0 = 220.2068679123761D+00 ) double precision p1 parameter ( p1 = 221.2135961699311D+00 ) double precision p2 parameter ( p2 = 112.0792914978709D+00 ) double precision p3 parameter ( p3 = 33.91286607838300D+00 ) double precision p4 parameter ( p4 = 6.373962203531650D+00 ) double precision p5 parameter ( p5 = 0.7003830644436881D+00 ) double precision p6 parameter ( p6 = 0.03526249659989109D+00 ) double precision pdf double precision q double precision q0 parameter ( q0 = 440.4137358247522D+00 ) double precision q1 parameter ( q1 = 793.8265125199484D+00 ) double precision q2 parameter ( q2 = 637.3336333788311D+00 ) double precision q3 parameter ( q3 = 296.5642487796737D+00 ) double precision q4 parameter ( q4 = 86.78073220294608D+00 ) double precision q5 parameter ( q5 = 16.06417757920695D+00 ) double precision q6 parameter ( q6 = 1.755667163182642D+00 ) double precision q7 parameter ( q7 = 0.08838834764831844D+00 ) double precision root2pi parameter ( root2pi = 2.506628274631001D+00 ) double precision z double precision zabs zabs = dabs ( z ) c c 37 < |Z|. c if ( 37.0D+00 .lt. zabs ) then pdf = 0.0D+00 p = 0.0D+00 c c |Z| <= 37. c else expntl = dexp ( - 0.5D+00 * zabs * zabs ) pdf = expntl / root2pi c c |Z| < CUTOFF = 10 / sqrt(2). c if ( zabs .lt. cutoff ) then p = expntl * (((((( & p6 * zabs & + p5 ) * zabs & + p4 ) * zabs & + p3 ) * zabs & + p2 ) * zabs & + p1 ) * zabs & + p0 ) / ((((((( & q7 * zabs & + q6 ) * zabs & + q5 ) * zabs & + q4 ) * zabs & + q3 ) * zabs & + q2 ) * zabs & + q1 ) * zabs & + q0 ) c c CUTOF <= |Z|. c else p = pdf / ( & zabs + 1.0D+00 / ( & zabs + 2.0D+00 / ( & zabs + 3.0D+00 / ( & zabs + 4.0D+00 / ( & zabs + 0.65D+00 ))))) end if end if if ( z .lt. 0.0D+00 ) then q = 1.0D+00 - p else q = p p = 1.0D+00 - q end if return end subroutine owen_values ( n_data, h, a, t ) c*********************************************************************72 c cc OWEN_VALUES returns some values of Owen's T function. c c Discussion: c c Owen's T function is useful for computation of the bivariate normal c distribution and the distribution of a skewed normal distribution. c c Although it was originally formulated in terms of the bivariate c normal function, the function can be defined more directly as c c T(H,A) = 1 / ( 2 * pi ) * c Integral ( 0 <= X <= A ) e^(-H^2*(1+X^2)/2) / (1+X^2) dX c c In Mathematica, the function can be evaluated by: c c fx = 1/(2*Pi) * Integrate [ E^(-h^2*(1+x^2)/2)/(1+x^2), {x,0,a} ] c c Modified: c c 25 March 2007 c c Author: c c John Burkardt c c Reference: c c Stephen Wolfram, c The Mathematica Book, c Fourth Edition, c Cambridge University Press, 1999, c ISBN: 0-521-64314-7, c LC: QA76.95.W65. c c Parameters: c c Input/output, integer N_DATA. The user sets N_DATA to 0 before the c first call. On each call, the routine increments N_DATA by 1, and c returns the corresponding data; when there is no more data, the c output value of N_DATA will be 0 again. c c Output, double precision H, a parameter. c c Output, double precision A, the upper limit of the integral. c c Output, double precision T, the value of the function. c implicit none integer n_max parameter ( n_max = 22 ) double precision a double precision a_vec(n_max) double precision h double precision h_vec(n_max) integer n_data double precision t double precision t_vec(n_max) save a_vec save h_vec save t_vec data a_vec / & 0.5000000000000000D+00, & 0.1000000000000000D+01, & 0.2000000000000000D+01, & 0.3000000000000000D+01, & 0.5000000000000000D+00, & 0.1000000000000000D+01, & 0.2000000000000000D+01, & 0.3000000000000000D+01, & 0.5000000000000000D+00, & 0.1000000000000000D+01, & 0.2000000000000000D+01, & 0.3000000000000000D+01, & 0.5000000000000000D+00, & 0.1000000000000000D+01, & 0.2000000000000000D+01, & 0.3000000000000000D+01, & 0.5000000000000000D+00, & 0.1000000000000000D+01, & 0.2000000000000000D+01, & 0.3000000000000000D+01, & 0.1000000000000000D+02, & 0.1000000000000000D+03 / data h_vec / & 0.1000000000000000D+01, & 0.1000000000000000D+01, & 0.1000000000000000D+01, & 0.1000000000000000D+01, & 0.5000000000000000D+00, & 0.5000000000000000D+00, & 0.5000000000000000D+00, & 0.5000000000000000D+00, & 0.2500000000000000D+00, & 0.2500000000000000D+00, & 0.2500000000000000D+00, & 0.2500000000000000D+00, & 0.1250000000000000D+00, & 0.1250000000000000D+00, & 0.1250000000000000D+00, & 0.1250000000000000D+00, & 0.7812500000000000D-02, & 0.7812500000000000D-02, & 0.7812500000000000D-02, & 0.7812500000000000D-02, & 0.7812500000000000D-02, & 0.7812500000000000D-02 / data t_vec / & 0.4306469112078537D-01, & 0.6674188216570097D-01, & 0.7846818699308410D-01, & 0.7929950474887259D-01, & 0.6448860284750376D-01, & 0.1066710629614485D+00, & 0.1415806036539784D+00, & 0.1510840430760184D+00, & 0.7134663382271778D-01, & 0.1201285306350883D+00, & 0.1666128410939293D+00, & 0.1847501847929859D+00, & 0.7317273327500385D-01, & 0.1237630544953746D+00, & 0.1737438887583106D+00, & 0.1951190307092811D+00, & 0.7378938035365546D-01, & 0.1249951430754052D+00, & 0.1761984774738108D+00, & 0.1987772386442824D+00, & 0.2340886964802671D+00, & 0.2479460829231492D+00 / if ( n_data .lt. 0 ) then n_data = 0 end if n_data = n_data + 1 if ( n_max .lt. n_data ) then n_data = 0 h = 0.0D+00 a = 0.0D+00 t = 0.0D+00 else h = h_vec(n_data) a = a_vec(n_data) t = t_vec(n_data) end if return end function q ( h, ah ) c*********************************************************************72 c cc Q computes (1/2) * p(H