subroutine BINOMINT (m, N, cl, p_lo, p_up, ierr) c Author: Glen Cowan c Date: 6-Jan-1998 c Computes the central confidence interval at a confidence level cl for c the binomial parameter p, given m successes observed in N trials. c Must be linked with FFINV, ALNGAM, XINBTA, BETAIN. implicit NONE c arguments integer ierr ! 0 = ok integer m integer N real cl real p_lo real p_up c local variables integer n1, n2 real alpha real FFINV ! quantile of F distribution real one_minus_beta real q c begin ierr = 0 if ( m .lt. 0 ) then ierr = 1 elseif ( m .gt. N ) then ierr = 2 elseif ( cl .lt. 0. ) then ierr = 3 elseif ( cl .gt. 1. ) then ierr = 4 endif if ( ierr .ne. 0 ) then p_lo = -1. p_up = -1. return ! ---------------------> exit endif alpha = (1.-cl)/2. if ( m .gt. 0 ) then n1 = 2*m n2 = 2*(N-m+1) q = FFINV (alpha, n1, n2, ierr) p_lo = FLOAT(m)*q / (FLOAT(N-m+1) + FLOAT(m)*q) elseif ( m .eq. 0 ) then p_lo = 0. endif one_minus_beta = (1.+cl)/2. if ( m .lt. N ) then n1 = 2*(m+1) n2 = 2*(N-m) q = FFINV (one_minus_beta, n1, n2, ierr) p_up = FLOAT(m+1)*q / (FLOAT(N-m) + FLOAT(m+1)*q) elseif ( m .eq. N ) then p_up = 1. endif return END