Click or drag to resize

StatQuantile Method (ReadOnlyDoubleMatrix, DoubleMatrix)

Returns the quantiles of the given data for the specified probabilities.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Quantile(
	ReadOnlyDoubleMatrix data,
	DoubleMatrix probabilities
)

Parameters

data
Type: Novacta.AnalyticsReadOnlyDoubleMatrix
The data.
probabilities
Type: Novacta.AnalyticsDoubleMatrix
The probabilities whose quantiles are to be computed.

Return Value

Type: DoubleMatrix
The data quantiles corresponding to the specified probabilities.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
-or-
probabilities is null.
ArgumentExceptionprobabilities has entries not belonging to the closed interval [0, 1].
Remarks

The quantile of a distribution LaTeX equation for the probability LaTeX equation can be defined as follows:

LaTeX equation

The method returns a DoubleMatrix instance which includes the quantiles of data. It has the same dimensions of probabilities. Let LaTeX equation be the Length of probabilities and define

LaTeX equation

Then the k-th linear position of the returned matrix is occupied by the quantile corresponding to LaTeX equation, say LaTeX equation. It is computed as proposed by Hyndman and Fan (1996)[1] . Let LaTeX equation be the Length of data and let

LaTeX equation

be the values in data sorted in ascending order. Value LaTeX equation is taken as the quantile corresponding to the probability

LaTeX equation

and quantile LaTeX equation is obtained by linear interpolation of the points

LaTeX equation

hence setting

  • LaTeX equation if LaTeX equation;
  • LaTeX equation if LaTeX equation;
  • LaTeX equation if LaTeX equation.

Examples

In the following example, the quantiles of the values in a data matrix are computed for probabilities .005, .50, .75, and .999.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class QuantileExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var matrix = DoubleMatrix.Dense(25, 4);
            for (int m = 0; m < matrix.Count; m++) {
                matrix[m] = 1 + m;
            }
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Create the probabilities.
            var probabilities = DoubleMatrix.Dense(2, 2);
            probabilities[0, 0] = .005;
            probabilities[1, 0] = .50;
            probabilities[0, 1] = .75;
            probabilities[1, 1] = .999;

            // Compute the data quantiles.
            var quantiles = Stat.Quantile(matrix, probabilities);

            Console.WriteLine();
            Console.WriteLine("Probabilities are:");
            Console.WriteLine(probabilities);

            Console.WriteLine();
            Console.WriteLine("Corresponding data quantiles are:");
            Console.WriteLine(quantiles);

            // Quantile is overloaded to accept data as a read-only matrix:
            // compute the quantiles using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var quantilesOfReadOnlyData = Stat.Quantile(readOnlyMatrix, probabilities);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. The quantiles are:");
            Console.WriteLine(quantilesOfReadOnlyData);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                26               51               76               
// 2                27               52               77               
// 3                28               53               78               
// 4                29               54               79               
// 5                30               55               80               
// 6                31               56               81               
// 7                32               57               82               
// 8                33               58               83               
// 9                34               59               84               
// 10               35               60               85               
// 11               36               61               86               
// 12               37               62               87               
// 13               38               63               88               
// 14               39               64               89               
// 15               40               65               90               
// 16               41               66               91               
// 17               42               67               92               
// 18               43               68               93               
// 19               44               69               94               
// 20               45               70               95               
// 21               46               71               96               
// 22               47               72               97               
// 23               48               73               98               
// 24               49               74               99               
// 25               50               75               100              
// 
// 
// 
// Probabilities are:
// 0.005            0.75             
// 0.5              0.999            
// 
// 
// 
// Corresponding data quantiles are:
// 1                75.5833333       
// 50.5             100              
// 
// 
// 
// Using read-only data. The quantiles are:
// 1                75.5833333       
// 50.5             100              
// 

Bibliography
[1] Hyndman, R.J. and Fan, Y., Sample Quantiles in Statistical Packages, Taylor and Francis, Ltd. on behalf of the American Statistical Association, in: The American Statistician, 50, 4, pp. 361-365. (1996), http://www.jstor.org/stable/2684934
See Also