Percentiles Ranks Example (C#)
[C#]
/* COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
* All rights reserved.
*
* Use of this copyright notice is precautionary only, and does not imply
* publication or disclosure. The content of this work contains confidential
* and proprietary information of Simplexar Software Limited. Any duplication,
* modification, distribution, or disclosure in any form, in whole, or in part,
* is strictly prohibited without express prior written permission.
*/
// Get namespaces.
using System;
using Simplexar.Statsar;
// Start namespace.
namespace Simplexar.Examples.Statsar
{
/// <summary>
/// This example uses the statistics calculator to perform percentiles
/// and rank statistics on a data sheet (e.g. interquartile range
/// and percentiles).
/// </summary>
public static class Example
{
/// <summary>
/// The application entry point.
/// </summary>
public static void Main()
{
try
{
RunExample();
}
catch(Exception exception)
{
Console.WriteLine(exception);
}
Console.WriteLine("Press ENTER to terminate.");
Console.ReadLine();
}
private static void RunExample()
{
// Create a calculator.
StatsCalculator calculator = new StatsCalculator();
// Use the calculator to load the sheet.
DataSheet sheet = calculator.Load(
@"..\..\..\..\..\Data\ExamResults.csv");
Console.WriteLine(sheet);
// Calculate percentile and rank statistics
// for the english result column.
Console.WriteLine("3rd quartile: {0}",
calculator.Quartile("EnglishResult", 3));
Console.WriteLine("7th decile: {0}",
calculator.Decile("EnglishResult", 7));
Console.WriteLine("45th percentile: {0}",
calculator.Percentile("EnglishResult", 0.45));
Console.WriteLine("Interquartile range: {0}",
calculator.InterquartileRange("EnglishResult"));
Console.WriteLine("Percent rank of 65: {0}",
calculator.PercentRank("EnglishResult", 65));
Console.WriteLine("Rank of 60: {0}",
calculator.Rank("EnglishResult", 60));
Console.Write("Ranks:");
int[] ranks = calculator.Ranks("EnglishResult");
foreach(int rank in ranks)
{
Console.Write(" {0}", rank);
}
Console.WriteLine();
Console.WriteLine();
}
}
}