public void ConstructorTest() { var F = new FDistribution(degrees1: 8, degrees2: 5); double mean = F.Mean; // 1.6666666666666667 double median = F.Median; // 1.0545096252132447 double var = F.Variance; // 7.6388888888888893 double cdf = F.DistributionFunction(x: 0.27); // 0.049463408057268315 double pdf = F.ProbabilityDensityFunction(x: 0.27); // 0.45120469723580559 double lpdf = F.LogProbabilityDensityFunction(x: 0.27); // -0.79583416831212883 double ccdf = F.ComplementaryDistributionFunction(x: 0.27); // 0.95053659194273166 double icdf = F.InverseDistributionFunction(p: cdf); // 0.27 double hf = F.HazardFunction(x: 0.27); // 0.47468419528555084 double chf = F.CumulativeHazardFunction(x: 0.27); // 0.050728620222091653 string str = F.ToString(CultureInfo.InvariantCulture); // F(x; df1 = 8, df2 = 5) Assert.AreEqual(1.6666666666666667, mean); Assert.AreEqual(1.0545096252132447, median); Assert.AreEqual(7.6388888888888893, var); Assert.AreEqual(0.050728620222091653, chf); Assert.AreEqual(0.049463408057268315, cdf); Assert.AreEqual(0.45120469723580559, pdf); Assert.AreEqual(-0.79583416831212883, lpdf); Assert.AreEqual(0.47468419528555084, hf); Assert.AreEqual(0.95053659194273166, ccdf); Assert.AreEqual(0.27, icdf); Assert.AreEqual("F(x; df1 = 8, df2 = 5)", str); }
/// <summary> /// Creates a new F-Test for a given statistic /// with given degrees of freedom. /// </summary> /// /// <param name="statistic">The test statistic.</param> /// <param name="d1">The degrees of freedom for the numerator.</param> /// <param name="d2">The degrees of freedom for the denominator.</param> /// public FTest(double statistic, int d1, int d2) : base(statistic) { base.Hypothesis = Hypothesis.OneUpper; StatisticDistribution = new FDistribution(d1, d2); PValue = 1.0 - StatisticDistribution.DistributionFunction(statistic); }
public void DistributionFunctionTest() { FDistribution f = new FDistribution(2, 3); Assert.AreEqual(f.DegreesOfFreedom1, 2); Assert.AreEqual(f.DegreesOfFreedom2, 3); double expected = 0.350480947161671; double actual = f.DistributionFunction(0.5); Assert.AreEqual(expected, actual, 1e-6); }
public void ConstructorTest() { var F = new FDistribution(degrees1: 8, degrees2: 5); double mean = F.Mean; // 1.6666666666666667 double median = F.Median; // 1.0545096252132447 double var = F.Variance; // 7.6388888888888893 double mode = F.Mode; // 0.5357142857142857 double cdf = F.DistributionFunction(x: 0.27); // 0.049463408057268315 double pdf = F.ProbabilityDensityFunction(x: 0.27); // 0.45120469723580559 double lpdf = F.LogProbabilityDensityFunction(x: 0.27); // -0.79583416831212883 double ccdf = F.ComplementaryDistributionFunction(x: 0.27); // 0.95053659194273166 double icdf = F.InverseDistributionFunction(p: cdf); // 0.27 double hf = F.HazardFunction(x: 0.27); // 0.47468419528555084 double chf = F.CumulativeHazardFunction(x: 0.27); // 0.050728620222091653 string str = F.ToString(CultureInfo.InvariantCulture); // F(x; df1 = 8, df2 = 5) Assert.AreEqual(0, F.Support.Min); Assert.AreEqual(double.PositiveInfinity, F.Support.Max); Assert.AreEqual(F.InverseDistributionFunction(0), F.Support.Min); Assert.AreEqual(F.InverseDistributionFunction(1), F.Support.Max); Assert.AreEqual(1.6666666666666667, mean); Assert.AreEqual(1.0545096252132447, median); Assert.AreEqual(7.6388888888888893, var); Assert.AreEqual(0.5357142857142857, mode); Assert.AreEqual(0.050728620222091653, chf); Assert.AreEqual(0.049463408057268315, cdf); Assert.AreEqual(0.45120469723580559, pdf); Assert.AreEqual(-0.79583416831212883, lpdf); Assert.AreEqual(0.47468419528555084, hf); Assert.AreEqual(0.95053659194273166, ccdf); Assert.AreEqual(0.27, icdf); Assert.AreEqual("F(x; df1 = 8, df2 = 5)", str); var range1 = F.GetRange(0.95); var range2 = F.GetRange(0.99); var range3 = F.GetRange(0.01); Assert.AreEqual(0.27118653875813753, range1.Min); Assert.AreEqual(4.8183195356568689, range1.Max); Assert.AreEqual(0.15078805233761733, range2.Min); Assert.AreEqual(10.289311046135927, range2.Max); Assert.AreEqual(0.1507880523376173, range3.Min); Assert.AreEqual(10.289311046135927, range3.Max); }
public void DistributionFunctionTest3() { double[] cdf = { 0, 0.0277778, 0.0816327, 0.140625, 0.197531, 0.25, 0.297521, 0.340278, 0.378698, 0.413265, 0.444444 }; FDistribution target = new FDistribution(4, 2); for (int i = 0; i < 11; i++) { double x = i / 10.0; double actual = target.DistributionFunction(x); double expected = cdf[i]; Assert.AreEqual(expected, actual, 1e-5); Assert.IsFalse(double.IsNaN(actual)); } }
public void Confirm_BetPrimeDistribution_Relative_to_F_Distribution() { double alpha = 4.0d; double beta = 6.0d; FDistribution fdist = new FDistribution((int)alpha * 2, (int)beta * 2); double fMean = fdist.Mean; double fPdf = (beta / alpha) * fdist.ProbabilityDensityFunction(4.0d); double fCdf = fdist.DistributionFunction(4.0d); var betaPrimeDist = new BetaPrimeDistribution(alpha, beta); double bpMean = (beta / alpha) * betaPrimeDist.Mean; double bpPdf = betaPrimeDist.ProbabilityDensityFunction((alpha / beta) * 4.0d); double bpCdf = betaPrimeDist.DistributionFunction((alpha / beta) * 4.0d); Assert.AreEqual(fMean, bpMean, 0.00000001, "mean should be equal"); Assert.AreEqual(fPdf, bpPdf, 0.00000001, "probability density should be equal"); Assert.AreEqual(fCdf, bpCdf, 0.00000001, "cumulative distribution should be equal"); //Beta Prime distribution is a scaled version of Pearson Type VI, which itself is scale of F distribution }
public void ComplementaryDistributionFunctionTest() { double actual; double expected; int[] nu1 = { 1, 2, 3, 4, 5 }; int[] nu2 = { 6, 7, 8, 9, 10 }; double[] x = { 2, 3, 4, 5, 6 }; double[] cdf = { 0.7930, 0.8854, 0.9481, 0.9788, 0.9919 }; FDistribution f; for (int i = 0; i < 5; i++) { f = new FDistribution(nu1[i], nu2[i]); expected = cdf[i]; actual = f.DistributionFunction(x[i]); Assert.AreEqual(expected, actual, 1e-4); f = new FDistribution(nu2[i], nu1[i]); actual = f.ComplementaryDistributionFunction(1.0 / x[i]); Assert.AreEqual(expected, actual, 1e-4); } }