Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | n | |||
real, | intent(in) | :: | p | |||
integer, | intent(in) | :: | r |
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