1
SUBROUTINE cdff(which,p,q,f,dfn,dfd,status,bound)
2
C**********************************************************************
4
C SUBROUTINE CDFF( WHICH, P, Q, F, DFN, DFD, STATUS, BOUND )
5
C Cumulative Distribution Function
12
C Calculates any one parameter of the F distribution
13
C given values for the others.
19
C WHICH --> Integer indicating which of the next four argument
20
C values is to be calculated from the others.
22
C iwhich = 1 : Calculate P and Q from F,DFN and DFD
23
C iwhich = 2 : Calculate F from P,Q,DFN and DFD
24
C iwhich = 3 : Calculate DFN from P,Q,F and DFD
25
C iwhich = 4 : Calculate DFD from P,Q,F and DFN
28
C P <--> The integral from 0 to F of the f-density.
33
C Input range: (0, 1].
37
C F <--> Upper limit of integration of the f-density.
38
C Input range: [0, +infinity).
39
C Search range: [0,1E300]
42
C DFN < --> Degrees of freedom of the numerator sum of squares.
43
C Input range: (0, +infinity).
44
C Search range: [ 1E-300, 1E300]
45
C DOUBLE PRECISION DFN
47
C DFD < --> Degrees of freedom of the denominator sum of squares.
48
C Input range: (0, +infinity).
49
C Search range: [ 1E-300, 1E300]
50
C DOUBLE PRECISION DFD
52
C STATUS <-- 0 if calculation completed correctly
53
C -I if input parameter number I is out of range
54
C 1 if answer appears to be lower than lowest
56
C 2 if answer appears to be higher than greatest
61
C BOUND <-- Undefined if STATUS is 0
63
C Bound exceeded by parameter number I if STATUS
66
C Lower search bound if STATUS is 1.
68
C Upper search bound if STATUS is 2.
74
C Formula 26.6.2 of Abramowitz and Stegun, Handbook of
75
C Mathematical Functions (1966) is used to reduce the computation
76
C of the cumulative distribution function for the F variate to
77
C that of an incomplete beta.
79
C Computation of other parameters involve a seach for a value that
80
C produces the desired value of P. The search relies on the
81
C monotinicity of P with the other parameter.
85
C The value of the cumulative F distribution is not necessarily
86
C monotone in either degrees of freedom. There thus may be two
87
C values that provide a given CDF value. This routine assumes
88
C monotonicity and will find an arbitrary one of the two values.
90
C**********************************************************************
93
PARAMETER (tol=1.0D-8)
95
PARAMETER (atol=1.0D-50)
96
DOUBLE PRECISION zero,inf
97
PARAMETER (zero=1.0D-300,inf=1.0D300)
99
C .. Scalar Arguments ..
100
DOUBLE PRECISION bound,dfd,dfn,f,p,q
103
C .. Local Scalars ..
104
DOUBLE PRECISION pq,fx,cum,ccum
105
LOGICAL qhi,qleft,qporq
107
C .. External Functions ..
108
DOUBLE PRECISION spmpar
111
C .. External Subroutines ..
112
EXTERNAL dinvr,dstinv,cumf
114
C .. Executable Statements ..
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
131
IF (.NOT. ((p.LT.0.0D0).OR. (p.GT.1.0D0))) GO TO 60
132
IF (.NOT. (p.LT.0.0D0)) GO TO 40
141
70 IF (which.EQ.1) GO TO 110
145
IF (.NOT. ((q.LE.0.0D0).OR. (q.GT.1.0D0))) GO TO 100
146
IF (.NOT. (q.LE.0.0D0)) GO TO 80
155
110 IF (which.EQ.2) GO TO 130
159
IF (.NOT. (f.LT.0.0D0)) GO TO 120
165
130 IF (which.EQ.3) GO TO 150
169
IF (.NOT. (dfn.LE.0.0D0)) GO TO 140
175
150 IF (which.EQ.4) GO TO 170
179
IF (.NOT. (dfd.LE.0.0D0)) GO TO 160
185
170 IF (which.EQ.1) GO TO 210
190
IF (.NOT. (abs(((pq)-0.5D0)-0.5D0).GT.
191
+ (3.0D0*spmpar(1)))) GO TO 200
192
IF (.NOT. (pq.LT.0.0D0)) GO TO 180
201
210 IF (.NOT. (which.EQ.1)) qporq = p .LE. q
203
C Select the minimum of P or Q
208
IF ((1).EQ. (which)) THEN
212
CALL cumf(f,dfn,dfd,p,q)
215
ELSE IF ((2).EQ. (which)) THEN
220
CALL dstinv(0.0D0,inf,0.5D0,0.5D0,5.0D0,atol,tol)
222
CALL dinvr(status,f,fx,qleft,qhi)
223
220 IF (.NOT. (status.EQ.1)) GO TO 250
224
CALL cumf(f,dfn,dfd,cum,ccum)
225
IF (.NOT. (qporq)) GO TO 230
230
240 CALL dinvr(status,f,fx,qleft,qhi)
233
250 IF (.NOT. (status.EQ.-1)) GO TO 280
234
IF (.NOT. (qleft)) GO TO 260
244
ELSE IF ((3).EQ. (which)) THEN
249
CALL dstinv(zero,inf,0.5D0,0.5D0,5.0D0,atol,tol)
251
CALL dinvr(status,dfn,fx,qleft,qhi)
252
290 IF (.NOT. (status.EQ.1)) GO TO 320
253
CALL cumf(f,dfn,dfd,cum,ccum)
254
IF (.NOT. (qporq)) GO TO 300
259
310 CALL dinvr(status,dfn,fx,qleft,qhi)
262
320 IF (.NOT. (status.EQ.-1)) GO TO 350
263
IF (.NOT. (qleft)) GO TO 330
273
ELSE IF ((4).EQ. (which)) THEN
278
CALL dstinv(zero,inf,0.5D0,0.5D0,5.0D0,atol,tol)
280
CALL dinvr(status,dfd,fx,qleft,qhi)
281
360 IF (.NOT. (status.EQ.1)) GO TO 390
282
CALL cumf(f,dfn,dfd,cum,ccum)
283
IF (.NOT. (qporq)) GO TO 370
288
380 CALL dinvr(status,dfd,fx,qleft,qhi)
291
390 IF (.NOT. (status.EQ.-1)) GO TO 420
292
IF (.NOT. (qleft)) GO TO 400