dbetai.f

Go to the documentation of this file.
00001 
00002 *DECK DBETAI
00003       DOUBLE PRECISION FUNCTION DBETAI (X, PIN, QIN)
00004 C***BEGIN PROLOGUE  DBETAI
00005 C***PURPOSE  Calculate the incomplete Beta function.
00006 C***LIBRARY   SLATEC (FNLIB)
00007 C***CATEGORY  C7F
00008 C***TYPE      DOUBLE PRECISION (BETAI-S, DBETAI-D)
00009 C***KEYWORDS  FNLIB, INCOMPLETE BETA FUNCTION, SPECIAL FUNCTIONS
00010 C***AUTHOR  Fullerton, W., (LANL)
00011 C***DESCRIPTION
00012 C
00013 C   DBETAI calculates the DOUBLE PRECISION incomplete beta function.
00014 C
00015 C   The incomplete beta function ratio is the probability that a
00016 C   random variable from a beta distribution having parameters PIN and
00017 C   QIN will be less than or equal to X.
00018 C
00019 C     -- Input Arguments -- All arguments are DOUBLE PRECISION.
00020 C   X      upper limit of integration.  X must be in (0,1) inclusive.
00021 C   PIN    first beta distribution parameter.  PIN must be .GT. 0.0.
00022 C   QIN    second beta distribution parameter.  QIN must be .GT. 0.0.
00023 C
00024 C***REFERENCES  Nancy E. Bosten and E. L. Battiste, Remark on Algorithm
00025 C                 179, Communications of the ACM 17, 3 (March 1974),
00026 C                 pp. 156.
00027 C***ROUTINES CALLED  D1MACH, DLBETA, XERMSG
00028 C***REVISION HISTORY  (YYMMDD)
00029 C   770701  DATE WRITTEN
00030 C   890531  Changed all specific intrinsics to generic.  (WRB)
00031 C   890911  Removed unnecessary intrinsics.  (WRB)
00032 C   890911  REVISION DATE from Version 3.2
00033 C   891214  Prologue converted to Version 4.0 format.  (BAB)
00034 C   900315  CALLs to XERROR changed to CALLs to XERMSG.  (THJ)
00035 C   920528  DESCRIPTION and REFERENCES sections revised.  (WRB)
00036 C***END PROLOGUE  DBETAI
00037       DOUBLE PRECISION X, PIN, QIN, ALNEPS, ALNSML, C, EPS, FINSUM, P,
00038      1  PS, Q, SML, TERM, XB, XI, Y, D1MACH, DLBETA, P1
00039       LOGICAL FIRST
00040       SAVE EPS, ALNEPS, SML, ALNSML, FIRST
00041       DATA FIRST /.TRUE./
00042 C***FIRST EXECUTABLE STATEMENT  DBETAI
00043       IF (FIRST) THEN
00044          EPS = D1MACH(3)
00045          ALNEPS = LOG (EPS)
00046          SML = D1MACH(1)
00047          ALNSML = LOG (SML)
00048       ENDIF
00049       FIRST = .FALSE.
00050 C
00051       IF (X .LT. 0.D0 .OR. X .GT. 1.D0) CALL XERMSG ('SLATEC', 'DBETAI',
00052      +   'X IS NOT IN THE RANGE (0,1)', 1, 2)
00053       IF (PIN .LE. 0.D0 .OR. QIN .LE. 0.D0) CALL XERMSG ('SLATEC',
00054      +   'DBETAI', 'P AND/OR Q IS LE ZERO', 2, 2)
00055 C
00056       Y = X
00057       P = PIN
00058       Q = QIN
00059       IF (Q.LE.P .AND. X.LT.0.8D0) GO TO 20
00060       IF (X.LT.0.2D0) GO TO 20
00061       Y = 1.0D0 - Y
00062       P = QIN
00063       Q = PIN
00064 C
00065  20   IF ((P+Q)*Y/(P+1.D0).LT.EPS) GO TO 80
00066 C
00067 C EVALUATE THE INFINITE SUM FIRST.  TERM WILL EQUAL
00068 C Y**P/BETA(PS,P) * (1.-PS)-SUB-I * Y**I / FAC(I) .
00069 C
00070       PS = Q - AINT(Q)
00071       IF (PS.EQ.0.D0) PS = 1.0D0
00072       XB = P*LOG(Y) - DLBETA(PS,P) - LOG(P)
00073       DBETAI = 0.0D0
00074       IF (XB.LT.ALNSML) GO TO 40
00075 C
00076       DBETAI = EXP (XB)
00077       TERM = DBETAI*P
00078       IF (PS.EQ.1.0D0) GO TO 40
00079       N = MAX (ALNEPS/LOG(Y), 4.0D0)
00080       DO 30 I=1,N
00081         XI = I
00082         TERM = TERM * (XI-PS)*Y/XI
00083         DBETAI = DBETAI + TERM/(P+XI)
00084  30   CONTINUE
00085 C
00086 C NOW EVALUATE THE FINITE SUM, MAYBE.
00087 C
00088  40   IF (Q.LE.1.0D0) GO TO 70
00089 C
00090       XB = P*LOG(Y) + Q*LOG(1.0D0-Y) - DLBETA(P,Q) - LOG(Q)
00091       IB = MAX (XB/ALNSML, 0.0D0)
00092       TERM = EXP(XB - IB*ALNSML)
00093       C = 1.0D0/(1.D0-Y)
00094       P1 = Q*C/(P+Q-1.D0)
00095 C
00096       FINSUM = 0.0D0
00097       N = Q
00098       IF (Q.EQ.DBLE(N)) N = N - 1
00099       DO 50 I=1,N
00100         IF (P1.LE.1.0D0 .AND. TERM/EPS.LE.FINSUM) GO TO 60
00101         XI = I
00102         TERM = (Q-XI+1.0D0)*C*TERM/(P+Q-XI)
00103 C
00104         IF (TERM.GT.1.0D0) IB = IB - 1
00105         IF (TERM.GT.1.0D0) TERM = TERM*SML
00106 C
00107         IF (IB.EQ.0) FINSUM = FINSUM + TERM
00108  50   CONTINUE
00109 C
00110  60   DBETAI = DBETAI + FINSUM
00111  70   IF (Y.NE.X .OR. P.NE.PIN) DBETAI = 1.0D0 - DBETAI
00112       DBETAI = MAX (MIN (DBETAI, 1.0D0), 0.0D0)
00113       RETURN
00114 C
00115  80   DBETAI = 0.0D0
00116       XB = P*LOG(MAX(Y,SML)) - LOG(P) - DLBETA(P,Q)
00117       IF (XB.GT.ALNSML .AND. Y.NE.0.0D0) DBETAI = EXP(XB)
00118       IF (Y.NE.X .OR. P.NE.PIN) DBETAI = 1.0D0 - DBETAI
00119 C
00120       RETURN
00121       END
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines