Click or drag to resize

StatSkewness Method (ReadOnlyDoubleMatrix, Boolean)

Returns the skewness of the specified data, eventually adjusted for bias.

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

Parameters

data
Type: Novacta.AnalyticsReadOnlyDoubleMatrix
The data.
adjustForBias
Type: SystemBoolean
If set to true signals that the skewness is adjusted for bias.

Return Value

Type: Double
The skewness of the specified data, eventually adjusted for bias.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
ArgumentExceptionadjustForBias is true and the number of entries in data 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.

Index LaTeX equation can be estimated through the coefficient

LaTeX equation

where

LaTeX equation

is the sample central moment of order LaTeX equation, LaTeX equation is the dataCount and

LaTeX equation

Note that LaTeX equation is undefined if the standard deviation of data is zero.

The statistic LaTeX equation is a biased estimator of LaTeX equation. However, provided that LaTeX equation is greater than 2, a correction for bias is defined and the kurtosis evaluated through the coefficient

LaTeX equation

If adjustForBias is set to false, then this method returns LaTeX equation if it is defined, otherwise NaN is returned.

If adjustForBias is set to true, then this methods 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 returned, otherwise NaN.

Examples

In the following example, the skewness of a data matrix is computed.

C#
using System;

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

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

            // Compute the data skewness.
            var skewness = Stat.Skewness(matrix, adjustForBias);

            Console.WriteLine();
            Console.WriteLine("Data skewness is:");
            Console.WriteLine(skewness);

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

            Console.WriteLine();
            Console.WriteLine("Using read-only data. The skewness is:");
            Console.WriteLine(skewnessOfReadOnlyData);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                
// 2                -3               
// 3                4                
// 
// 
// 
// Data skewness is:
// -1.1007155393126171
// 
// Using read-only data. The skewness is:
// -1.1007155393126171

See Also