/// <summary> /// Gets the complementary cumulative distribution function /// (ccdf) for this distribution evaluated at point <c>x</c>. /// This function is also known as the Survival function. /// </summary> /// /// <remarks> /// The Complementary Cumulative Distribution Function (CCDF) is /// the complement of the Cumulative Distribution Function, or 1 /// minus the CDF. /// </remarks> /// public override double ComplementaryDistributionFunction(params double[] x) { if (Dimension == 1) { double stdDev = Math.Sqrt(Covariance[0, 0]); double z = (x[0] - mean[0]) / stdDev; if (stdDev == 0) { return((x[0] == mean[0]) ? 0 : 1); } return(Normal.Complemented(z)); } if (Dimension == 2) { double sigma1 = Math.Sqrt(Covariance[0, 0]); double sigma2 = Math.Sqrt(Covariance[1, 1]); double rho = Covariance[0, 1] / (sigma1 * sigma2); if (Double.IsNaN(rho)) { return((x.IsEqual(mean)) ? 0 : 1); } double z = (x[0] - mean[0]) / sigma1; double w = (x[1] - mean[1]) / sigma2; return(Normal.BivariateComplemented(z, w, rho)); } throw new NotSupportedException("The cumulative distribution " + "function is only available for up to two dimensions."); }
public void BatchTest2() { double x = 16.6; double phi = Normal.Function(x); double phic = Normal.Complemented(x); double hphic = Normal.HighAccuracyComplemented(x); double hphi = Normal.HighAccuracyFunction(x); Assert.AreEqual(1.0, phi); Assert.AreEqual(3.4845465199504055E-62, phic); Assert.AreEqual(0.99999999999999556, hphi); Assert.AreEqual(3.48454651995264E-62, hphic); }
public void BatchTest() { double x = 0.42; double phi = Normal.Function(x); double phic = Normal.Complemented(x); double inv = Normal.Inverse(x); double hphic = Normal.Complemented(x); double hphi = Normal.HighAccuracyFunction(x); Assert.AreEqual(0.66275727315175048, phi); Assert.AreEqual(0.33724272684824952, phic); Assert.AreEqual(-0.20189347914185085, inv); Assert.AreEqual(0.66275727315175048, hphi); Assert.AreEqual(0.33724272684824946, hphic, 1e-10); }
/// <summary> /// Gets the complementary cumulative distribution function /// (ccdf) for this distribution evaluated at point <c>x</c>. /// This function is also known as the Survival function. /// </summary> /// /// <param name="x">A single point in the distribution range.</param> /// public override double ComplementaryDistributionFunction(double x) { return(Normal.Complemented((x - mean) / stdDev)); }
/// <summary> /// Computes the cumulative probability at <c>t</c> of the /// non-central T-distribution with DF degrees of freedom /// and non-centrality parameter. /// </summary> /// /// <remarks> /// This function is based on the original work done by /// Russell Lent hand John Burkardt, shared under the /// LGPL license. Original FORTRAN code can be found at: /// http://people.sc.fsu.edu/~jburkardt/f77_src/asa243/asa243.html /// </remarks> /// private static double distributionFunctionLowerTail(double t, double df, double delta) { double alnrpi = 0.57236494292470008707; double errmax = 1.0E-10; int itrmax = 100; double r2pi = 0.79788456080286535588; if (df <= 0.0) { throw new ArgumentOutOfRangeException("df", "Degrees of freedom must be positive."); } double tt; double del; bool negdel; if (t < 0.0) { tt = -t; del = -delta; negdel = true; } else { tt = t; del = delta; negdel = false; } // Initialize twin series. double en = 1.0; double x = t * t / (t * t + df); double value = 0; if (x <= 0.0) { // upper tail of normal cumulative function value += Normal.Complemented(del); if (negdel) { value = 1.0 - value; } return(value); } double lambda = del * del; double p = 0.5 * Math.Exp(-0.5 * lambda); double q = r2pi * p * del; double s = 0.5 - p; double a = 0.5; double b = 0.5 * df; double rxb = Math.Pow(1.0 - x, b); double albeta = alnrpi + Gamma.Log(b) - Gamma.Log(a + b); double xodd = Beta.Incomplete(a, b, x); double godd = 2.0 * rxb * Math.Exp(a * Math.Log(x) - albeta); double xeven = 1.0 - rxb; double geven = b * x * rxb; value = p * xodd + q * xeven; // Repeat until convergence. while (true) { a = a + 1.0; xodd = xodd - godd; xeven = xeven - geven; godd = godd * x * (a + b - 1.0) / a; geven = geven * x * (a + b - 0.5) / (a + 0.5); p = p * lambda / (2.0 * en); q = q * lambda / (2.0 * en + 1.0); s = s - p; en = en + 1.0; value = value + p * xodd + q * xeven; double errbd = 2.0 * s * (xodd - godd); if (errbd <= errmax) { break; } if (itrmax < en) { throw new ConvergenceException("Maximum number of iterations reached."); } } // upper tail of normal cumulative function value = value + Normal.Complemented(del); if (negdel) { value = 1.0 - value; } return(value); }
/// <summary> /// Gets the complementary cumulative distribution function /// (ccdf) for this distribution evaluated at point <c>x</c>. /// This function is also known as the Survival function. /// </summary> /// /// <param name="x">A single point in the distribution range.</param> /// public override double ComplementaryDistributionFunction(double x) { double ccdf = Normal.Complemented((x - mean) / stdDev); return(ccdf); }
/// <summary> /// Gets the complementary cumulative distribution function /// (ccdf) for this distribution evaluated at point <c>x</c>. /// This function is also known as the Survival function. /// </summary> /// /// <param name="x">A single point in the distribution range.</param> /// protected internal override double InnerComplementaryDistributionFunction(double x) { return(Normal.Complemented((x - mean) / stdDev)); }