/// <summary>
        /// Returns the sum of the terms <tt>k+1</tt> to infinity of the Negative
        /// Binomial distribution.
        /// <pre>
        ///   inf
        ///   --  ( n+j-1 )   n      j
        ///   >   (       )  p  (1-p)
        ///   --  (   j   )
        ///  j=k+1
        /// </pre>
        /// The terms are not computed individually; instead the incomplete
        /// beta integral is employed, according to the formula
        /// <para>
        /// y = negativeBinomialComplemented( k, n, p ) = Gamma.incompleteBeta( k+1, n, 1-p ).
        ///
        /// All arguments must be positive,
        /// </para>
        /// </summary>
        /// <param name="k"> end term. </param>
        /// <param name="n"> the number of trials. </param>
        /// <param name="p"> the probability of success (must be in <tt>(0.0,1.0)</tt>). </param>
        /// <returns> result </returns>
        public static double negativeBinomialComplemented(int k, int n, double p)
        {
            if ((p < 0.0) || (p > 1.0))
            {
                throw new System.ArgumentException();
            }
            if (k < 0)
            {
                return(0.0);
            }

            return(GammaFunctions.incompleteBeta(k + 1, n, 1.0 - p));
        }
        /// <summary>
        /// Returns the integral from minus infinity to <tt>t</tt> of the Student-t
        /// distribution with <tt>k &gt; 0</tt> degrees of freedom.
        /// <pre>
        ///                                      t
        ///                                      -
        ///                                     | |
        ///              -                      |         2   -(k+1)/2
        ///             | ( (k+1)/2 )           |  (     x   )
        ///       ----------------------        |  ( 1 + --- )        dx
        ///                     -               |  (      k  )
        ///       sqrt( k pi ) | ( k/2 )        |
        ///                                   | |
        ///                                    -
        ///                                   -inf.
        /// </pre>
        /// Relation to incomplete beta integral:
        /// <para>
        /// <tt>1 - studentT(k,t) = 0.5 * Gamma.incompleteBeta( k/2, 1/2, z )</tt>
        /// where <tt>z = k/(k + t**2)</tt>.
        /// </para>
        /// <para>
        /// Since the function is symmetric about <tt>t=0</tt>, the area under the
        /// right tail of the density is found by calling the function
        /// with <tt>-t</tt> instead of <tt>t</tt>.
        ///
        /// </para>
        /// </summary>
        /// <param name="k"> degrees of freedom. </param>
        /// <param name="t"> integration end point. </param>
        /// <returns> result </returns>
        /// <exception cref="ArithmeticException"> error </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static double studentT(double k, double t) throws ArithmeticException
        public static double studentT(double k, double t)
        {
            if (k <= 0)
            {
                throw new System.ArgumentException();
            }
            if (t == 0)
            {
                return(0.5);
            }

            double cdf = 0.5 * GammaFunctions.incompleteBeta(0.5 * k, 0.5, k / (k + t * t));

            if (t >= 0)
            {
                cdf = 1.0 - cdf;   // fixes bug reported by [email protected]
            }

            return(cdf);
        }
        /// <summary>
        /// Returns the sum of the terms <tt>k+1</tt> through <tt>n</tt> of the Binomial
        /// probability density.
        /// <pre>
        ///   n
        ///   --  ( n )   j      n-j
        ///   >   (   )  p  (1-p)
        ///   --  ( j )
        ///  j=k+1
        /// </pre>
        /// The terms are not summed directly; instead the incomplete
        /// beta integral is employed, according to the formula
        /// <para>
        /// <tt>y = binomialComplemented( k, n, p ) = Gamma.incompleteBeta( k+1, n-k, p )</tt>.
        /// </para>
        /// <para>
        /// All arguments must be positive,
        /// </para>
        /// </summary>
        /// <param name="k"> end term. </param>
        /// <param name="n"> the number of trials. </param>
        /// <param name="p"> the probability of success (must be in <tt>(0.0,1.0)</tt>). </param>
        /// <returns> result </returns>
        /// <exception cref="ArithmeticException"> error </exception>
        public static double binomialComplemented(int k, int n, double p)
        {
            if ((p < 0.0) || (p > 1.0))
            {
                throw new System.ArgumentException();
            }
            if ((k < 0) || (n < k))
            {
                throw new System.ArgumentException();
            }

            if (k == n)
            {
                return(0.0);
            }
            if (k == 0)
            {
                return(1.0 - Math.Pow(1.0 - p, n - k));
            }

            return(GammaFunctions.incompleteBeta(k + 1, n - k, p));
        }
 /// <summary>
 /// Returns the area from zero to <tt>x</tt> under the beta density
 /// function.
 /// <pre>
 ///                          x
 ///            -             -
 ///           | (a+b)       | |  a-1      b-1
 /// P(x)  =  ----------     |   t    (1-t)    dt
 ///           -     -     | |
 ///          | (a) | (b)   -
 ///                         0
 /// </pre>
 /// This function is identical to the incomplete beta
 /// integral function <tt>Gamma.incompleteBeta(a, b, x)</tt>.
 ///
 /// The complemented function is
 ///
 /// <tt>1 - P(1-x)  =  Gamma.incompleteBeta( b, a, x )</tt>;
 /// </summary>
 /// <param name="a"> a </param>
 /// <param name="b"> b </param>
 /// <param name="x"> x </param>
 /// <returns> result </returns>
 /// <exception cref="ArithmeticException"> error </exception>
 public static double beta(double a, double b, double x)
 {
     return(GammaFunctions.incompleteBeta(a, b, x));
 }
 /// <summary>
 /// Returns the area under the right hand tail (from <tt>x</tt> to
 /// infinity) of the beta density function.
 ///
 /// This function is identical to the incomplete beta
 /// integral function <tt>Gamma.incompleteBeta(b, a, x)</tt>.
 /// </summary>
 /// <param name="a"> a </param>
 /// <param name="b"> b </param>
 /// <param name="x"> x </param>
 /// <returns> result </returns>
 /// <exception cref="ArithmeticException"> error </exception>
 public static double betaComplemented(double a, double b, double x)
 {
     return(GammaFunctions.incompleteBeta(b, a, x));
 }