Browse Source

ExcelFunctions: PERCENTILE

pull/194/head
Christoph Ruegg 13 years ago
parent
commit
72fc095d5a
  1. 5
      src/Numerics/ExcelFunctions.cs
  2. 24
      src/UnitTests/ExcelTests.cs

5
src/Numerics/ExcelFunctions.cs

@ -101,6 +101,11 @@ namespace MathNet.Numerics
}
}
public static double PERCENTILE(double[] array, double k)
{
return array.QuantileCustom(k, QuantileDefinition.Excel);
}
public static double PERCENTRANK(double[] array, double x)
{
return array.QuantileRank(x, RankDefinition.Min);

24
src/UnitTests/ExcelTests.cs

@ -119,6 +119,30 @@ namespace MathNet.Numerics.UnitTests
Assert.That(ExcelFunctions.GAMMAINV(0.9999, 2, 1.5), Is.EqualTo(17.63455683374).Within(1e-8), "G1");
}
[Test]
public void PERCENTILE()
{
var array = new Double[] { 1, 8, 12, 7, 2, 9, 10, 4 };
Assert.That(ExcelFunctions.PERCENTILE(array, 0.00), Is.EqualTo(1.00000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.01), Is.EqualTo(1.07000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.10), Is.EqualTo(1.70000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.40), Is.EqualTo(6.40000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.50), Is.EqualTo(7.50000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.90), Is.EqualTo(10.60000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.99), Is.EqualTo(11.86000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 1.00), Is.EqualTo(12.00000000000).Within(1e-8));
array = new Double[] { 1, 9, 12, 7, 2, 9, 10, 2 };
Assert.That(ExcelFunctions.PERCENTILE(array, 0.00), Is.EqualTo(1.00000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.01), Is.EqualTo(1.07000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.10), Is.EqualTo(1.70000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.40), Is.EqualTo(6.00000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.50), Is.EqualTo(8.00000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.90), Is.EqualTo(10.60000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 0.99), Is.EqualTo(11.86000000000).Within(1e-8));
Assert.That(ExcelFunctions.PERCENTILE(array, 1.00), Is.EqualTo(12.00000000000).Within(1e-8));
}
[Test]
public void QUARTILE()
{

Loading…
Cancel
Save