bin_prob Function

public function bin_prob(n, p, r) result(fn_val)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n
real, intent(in) :: p
integer, intent(in) :: r

Return Value real


Contents

Source Code


Source Code

FUNCTION bin_prob(n, p, r) RESULT(fn_val)
!     Calculate a binomial probability

INTEGER, INTENT(IN) :: n, r
REAL, INTENT(IN)    :: p
REAL                :: fn_val

!     Local variable
REAL                :: one = 1.0

fn_val = EXP( lngamma(DBLE(n+1)) - lngamma(DBLE(r+1)) - lngamma(DBLE(n-r+1)) &
              + r*LOG(p) + (n-r)*LOG(one - p) )
RETURN

END FUNCTION bin_prob