1
SUBROUTINE cdfnor(which,p,q,x,mean,sd,status,bound)
2
C**********************************************************************
4
C SUBROUTINE CDFNOR( WHICH, P, Q, X, MEAN, SD, STATUS, BOUND )
5
C Cumulative Distribution Function
12
C Calculates any one parameter of the normal
13
C distribution given values for the others.
19
C WHICH --> Integer indicating which of the next parameter
20
C values is to be calculated using values of the others.
22
C iwhich = 1 : Calculate P and Q from X,MEAN and SD
23
C iwhich = 2 : Calculate X from P,Q,MEAN and SD
24
C iwhich = 3 : Calculate MEAN from P,Q,X and SD
25
C iwhich = 4 : Calculate SD from P,Q,X and MEAN
28
C P <--> The integral from -infinity to X of the normal density.
33
C Input range: (0, 1].
37
C X < --> Upper limit of integration of the normal-density.
38
C Input range: ( -infinity, +infinity)
41
C MEAN <--> The mean of the normal density.
42
C Input range: (-infinity, +infinity)
43
C DOUBLE PRECISION MEAN
45
C SD <--> Standard Deviation of the normal density.
46
C Input range: (0, +infinity).
49
C STATUS <-- 0 if calculation completed correctly
50
C -I if input parameter number I is out of range
51
C 1 if answer appears to be lower than lowest
53
C 2 if answer appears to be higher than greatest
58
C BOUND <-- Undefined if STATUS is 0
60
C Bound exceeded by parameter number I if STATUS
63
C Lower search bound if STATUS is 1.
65
C Upper search bound if STATUS is 2.
73
C A slightly modified version of ANORM from
75
C Cody, W.D. (1993). "ALGORITHM 715: SPECFUN - A Portabel FORTRAN
76
C Package of Special Function Routines and Test Drivers"
77
C acm Transactions on Mathematical Software. 19, 22-32.
79
C is used to calulate the cumulative standard normal distribution.
81
C The rational functions from pages 90-95 of Kennedy and Gentle,
82
C Statistical Computing, Marcel Dekker, NY, 1980 are used as
83
C starting values to Newton's Iterations which compute the inverse
84
C standard normal. Therefore no searches are necessary for any
87
C For X < -15, the asymptotic expansion for the normal is used as
88
C the starting value in finding the inverse standard normal.
89
C This is formula 26.2.12 of Abramowitz and Stegun.
95
C The normal density is proportional to
96
C exp( - 0.5 * (( X - MEAN)/SD)**2)
99
C**********************************************************************
100
C .. Scalar Arguments ..
101
DOUBLE PRECISION bound,mean,p,q,sd,x
104
C .. Local Scalars ..
105
DOUBLE PRECISION pq,z
107
C .. External Functions ..
108
DOUBLE PRECISION dinvnr,spmpar
109
EXTERNAL dinvnr,spmpar
111
C .. External Subroutines ..
114
C .. Intrinsic Functions ..
118
IF (.NOT. ((which.LT.1).OR. (which.GT.4))) GO TO 30
119
IF (.NOT. (which.LT.1)) GO TO 10
127
30 IF (which.EQ.1) GO TO 70
128
IF (.NOT. ((p.LE.0.0D0).OR. (p.GT.1.0D0))) GO TO 60
129
IF (.NOT. (p.LE.0.0D0)) GO TO 40
138
70 IF (which.EQ.1) GO TO 110
139
IF (.NOT. ((q.LE.0.0D0).OR. (q.GT.1.0D0))) GO TO 100
140
IF (.NOT. (q.LE.0.0D0)) GO TO 80
149
110 IF (which.EQ.1) GO TO 150
151
IF (.NOT. (abs(((pq)-0.5D0)-0.5D0).GT.
152
+ (3.0D0*spmpar(1)))) GO TO 140
153
IF (.NOT. (pq.LT.0.0D0)) GO TO 120
162
150 IF (which.EQ.4) GO TO 170
163
IF (.NOT. (sd.LE.0.0D0)) GO TO 160
169
170 IF ((1).EQ. (which)) THEN
173
ELSE IF ((2).EQ. (which)) THEN
177
ELSE IF ((3).EQ. (which)) THEN
181
ELSE IF ((4).EQ. (which)) THEN