geocdf(3f) - [M_datapac:CUMULATIVE_DISTRIBUTION] compute the geometric
cumulative distribution function
SUBROUTINE GEOCDF(X,P,Cdf)
REAL(kind=wp),intent(in) :: X
REAL(kind=wp),intent(in) :: P
REAL(kind=wp),intent(out) :: Cdf
GEOCDF(3f) computes the cumulative distribution function value at the
REAL value X for the geometric distribution with precision
precision 'Bernoulli probability' parameter = P.
The geometric distribution used herein herein has mean = (1-P)/P and
standard deviation = sqrt((1-P)/(P*P))).
This distribution is defined for all non-negative integer X where X =
0, 1, 2, ... . This distribution has the probability function
f(X) = P * (1-P)**X
The geometric distribution is the distribution of the number of
failures before obtaining 1 success in an indefinite sequence of
Bernoulli (0,1) trials where the probability of success in a precision
trial = P.
Note that even though the input to this cumulative distribution
function subroutine for this discrete distribution should (under normal
circumstances) be a discrete integer value, the input variable X is REAL.
X has been specified as REAL so as to conform with the datapac convention
that all input ****data**** (as opposed to sample size, for example)
variables to all datapac subroutines are.
This convention is based on the belief that
1. A mixture of modes (floating point versus integer) is inconsistent
and an unnecessary complication in a data analysis; and
2. Floating point machine arithmetic (as opposed to integer
arithmetic) is the more natural mode for doing data analysis.
X The value at which the cumulative distribution function is
to be evaluated. X should be non-negative and integral-valued.
P The value of the 'Bernoulli probability' parameter for the
geometric distribution. P should be between 0.0 (exclusively)
and 1.0 (exclusively).
CDF The cumulative distribution function value for the geometric
distribution
Sample program:
program demo_geocdf
use M_datapac, only : geocdf
implicit none
! call geocdf(x,y)
end program demo_geocdf
Results:
The original DATAPAC library was written by James Filliben of the
Statistical Engineering Division, National Institute of Standards
and Technology.
John Urban, 2022.05.31
CC0-1.0
* Feller, An Introduction to Probability Theory and its Applications,
Volume 1, Edition 2, 1957, pages 155-157, 210.
* National Bureau of Standards Applied Mathematics Series 55, 1964,
page 929.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | X | |||
real(kind=wp), | intent(in) | :: | P | |||
real(kind=wp), | intent(out) | :: | Cdf |
SUBROUTINE GEOCDF(X,P,Cdf) REAL(kind=wp),intent(in) :: X REAL(kind=wp),intent(in) :: P REAL(kind=wp),intent(out) :: Cdf REAL(kind=wp) :: del , fintx INTEGER intx ! CHECK THE INPUT ARGUMENTS FOR ERRORS ! IF ( P<=0.0_wp .OR. P>=1.0_wp ) THEN WRITE (G_IO,99001) WRITE (G_IO,99004) P Cdf = 0.0_wp ELSEIF ( X<0.0_wp ) THEN WRITE (G_IO,99002) WRITE (G_IO,99004) X Cdf = 0.0_wp ELSE intx = X + 0.0001_wp fintx = intx del = X - fintx IF ( del<0.0_wp ) del = -del IF ( del>0.001_wp ) THEN WRITE (G_IO,99003) WRITE (G_IO,99004) X ENDIF Cdf = 1.0_wp - (1.0_wp-P)**(X+1.0_wp) ENDIF 99001 FORMAT(' ***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE GEOCDF SUBROUTINE IS OUTSIDE THE ALLOWABLE (0,1) INTERVAL *****') 99002 FORMAT(' ***** NON-FATAL DIAGNOSTIC--THE FIRST INPUT ARGUMENT TO THE GEOCDF SUBROUTINE IS NEGATIVE *****') 99003 FORMAT(' ***** NON-FATAL DIAGNOSTIC--THE FIRST INPUT ARGUMENT TO THE GEOCDF SUBROUTINE IS NON-INTEGRAL *****') 99004 FORMAT(' ***** THE VALUE OF THE ARGUMENT IS ',E15.8,' *****') END SUBROUTINE GEOCDF