lib/rubystats/modules.rb
# Evaluates of continued fraction part of incomplete beta function.
# Based on an idea from Numerical Recipes (W.H. Press et al, 1992).
# Author:: Jaco van Kooten
Evaluates of continued fraction part of incomplete beta function.
Based on an idea from Numerical Recipes (W.H.
Evaluates of continued fraction part of incomplete beta function . Based on an idea from Numerical Recipes ( W . H .
def beta_fraction(x, p, q) 
      c = 1.0
      sum_pq  = p + q
      p_plus  = p + 1.0
      p_minus = p - 1.0
      h = 1.0 - sum_pq * x / p_plus
      if h.abs < XMININ 
        h = XMININ
      end
      h     = 1.0 / h
      frac  = h
      m     = 1
      delta = 0.0
      while (m <= MAX_ITERATIONS) && ((delta - 1.0).abs > PRECISION) 
        m2 = 2 * m
        d = m * (q - m) * x / ( (p_minus + m2) * (p + m2))
        h = 1.0 + d * h
        if h.abs < XMININ
          h = XMININ
        end
        h = 1.0 / h
        c = 1.0 + d / c
        if c.abs < XMININ
          c = XMININ
        end
        frac *= (h * c)
        d = -(p + m) * (sum_pq + m) * x / ((p + m2) * (p_plus + m2))
        h = 1.0 + d * h
        if h.abs < XMININ
          h = XMININ
        end
        h = 1.0 / h
        c = 1.0 + d / c
        if c.abs < XMININ
          c = XMININ
        end
        delta = h * c
        frac *= delta
        m += 1
      end
      return frac
    end
def beta_fraction ( x , p , q ) c = 1.0 sum_pq = p + q p_plus = p + 1.0 p_minus = p - 1.0 h = 1.0 - sum_pq * x / p_plus if h . abs < XMININ h = XMININ end h = 1.0 / h frac = h m = 1 delta = 0.0 while ( m <= MAX_ITERATIONS ) && ( ( delta - 1.0 ) . abs > PRECISION ) m2 = 2 * m d = m * ( q - m ) * x / ( ( p_minus + m2 ) * ( p + m2 ) ) h = 1.0 + d * h if h . abs < XMININ h = XMININ end h = 1.0 / h c = 1.0 + d / c if c . abs < XMININ c = XMININ end frac *= ( h * c ) d = - ( p + m ) * ( sum_pq + m ) * x / ( ( p + m2 ) * ( p_plus + m2 ) ) h = 1.0 + d * h if h . abs < XMININ h = XMININ end h = 1.0 / h c = 1.0 + d / c if c . abs < XMININ c = XMININ end delta = h * c frac *= delta m += 1 end return frac end
Evaluates of continued fraction part of incomplete beta function.
Evaluates of continued fraction part of incomplete beta function .
# even index for d # odd index for d
x
<not_specific>
p
<not_specific>
q
<not_specific>