Click or drag to resize

StatSkewness Method (DoubleMatrix, Boolean, DataOperation)

Returns the skewness of each row or column in the specified data, eventually adjusted for bias.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Skewness(
	DoubleMatrix data,
	bool adjustForBias,
	DataOperation dataOperation
)

Parameters

data
Type: Novacta.AnalyticsDoubleMatrix
The data.
adjustForBias
Type: SystemBoolean
If set to true signals that the skewness is adjusted for bias.
dataOperation
Type: Novacta.AnalyticsDataOperation
A constant to specify if the skewness is to be computed for rows or columns.

Return Value

Type: DoubleMatrix
The skewness of each row or column in the specified data, eventually adjusted for bias.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
ArgumentExceptiondataOperation is not a field of DataOperation.
-or-
adjustForBias is true, dataOperation is OnRows and the data number of columns is less than 3.
-or-
adjustForBias is true, dataOperation is OnColumns and the data number of rows is less than 3.
Remarks

The skewness of a random variable LaTeX equation can be defined as follows:

LaTeX equation

where LaTeX equation and LaTeX equation are the cumulants of order 2 and 3, respectively, and

LaTeX equation

is the LaTeX equation central moment of order LaTeX equation.

By interpreting the rows or the columns of data as samples drawn from random variables, this method returns the skewness estimates of such variables. Let LaTeX equation and LaTeX equation be the data number of rows and columns, respectively, and define

LaTeX equation

Operating on rows

If dataOperation is OnRows, then the method returns a column vector whose length equals the number of rows of data. The i-th entry of such column returns the skewness of the i-th data row, say LaTeX equation

The LaTeX equation parameter can be estimated through the coefficient

LaTeX equation

where

LaTeX equation

is the sample LaTeX equation-th central moment of the i-th row.

Note that LaTeX equation is undefined if the standard deviation of the i-th row of data is zero.

The statistic LaTeX equation is a biased estimator of LaTeX equation However, provided that the number of columns in data is greater than 3, it can be corrected for bias and the corresponding kurtosis evaluated through the coefficient

LaTeX equation

If adjustForBias is set to false, then LaTeX equation is estimated through LaTeX equation if it is defined, otherwise the i-th position in the returned value evaluates to NaN.

If adjustForBias is set to true, then this method operates as follows.

  • If LaTeX equation is less than 4, i.e. the correction for bias is undefined, then an exception is thrown.
  • Differently, if LaTeX equation is defined, then LaTeX equation is stored in the i-th position of the returned value, otherwise such position stores NaN.

Operating on columns

If dataOperation is OnColumns, then the method returns a row vector whose length is the data number of columns. The j-th entry of the returned row exposes the skewness of the j-th data column, say LaTeX equation

The LaTeX equation parameter can be estimated through the coefficient

LaTeX equation

where

LaTeX equation

is the sample LaTeX equation-th central moment of the j-th column.

Note that LaTeX equation is undefined if the standard deviation of the j-th column of data is zero.

The statistic LaTeX equation is a biased estimator of LaTeX equation. However, provided that the number of rows in data is greater than 2, it can be corrected for bias and the corresponding skewness evaluated through the coefficient

LaTeX equation

If adjustForBias is set to false, then LaTeX equation is estimated through LaTeX equation if it is defined, otherwise the j-th position in the returned value evaluates to NaN.

If adjustForBias is set to true, then this method operates as follows.

  • If LaTeX equation is less than 3, i.e. the correction for bias is undefined, then an exception is thrown.
  • Differently, if LaTeX equation is defined, then LaTeX equation is stored in the j-th position of the returned value, otherwise such position stores NaN.

Examples

In the following example, row and column skewness estimates in a data matrix are computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class SkewnessExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[20] {
                1, 2, -3,  6, -2,
                2, 2,  2,  0,  7,
               -3, 2,  3,  2,  9,
                5, 2,  7, -1, -4
            };
            var matrix = DoubleMatrix.Dense(4, 5, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Skewness can be adjusted for bias.
            bool adjustForBias = true; 

            // Compute the skewness on columns.
            var skewnessOnColumns = Stat.Skewness(matrix, adjustForBias, DataOperation.OnColumns);

            Console.WriteLine();
            Console.WriteLine("Skewness on columns:");
            Console.WriteLine(skewnessOnColumns);

            // Skewness is overloaded to accept data as a read-only matrix:
            // compute the skewness on rows using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var skewnessOnRows = Stat.Skewness(readOnlyMatrix, adjustForBias, DataOperation.OnRows);

            Console.WriteLine();
            Console.WriteLine("Skewness on rows:");
            Console.WriteLine(skewnessOnRows);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                -3               6                -2               
// 2                2                2                0                7                
// -3               2                3                2                9                
// 5                2                7                -1               -4               
// 
// 
// 
// Skewness on columns:
// -0.436662085     NaN              -0.355715685     1.13762437       0                
// 
// 
// 
// Skewness on rows:
// 0.603194073      
// 1.57340612       
// 0.458582855      
// -0.208147907     
// 

See Also