Click or drag to resize

StatStandardDeviation Method (ReadOnlyDoubleMatrix, Boolean)

Returns the standard deviation 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 StandardDeviation(
	ReadOnlyDoubleMatrix data,
	bool adjustForBias
)

Parameters

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

Return Value

Type: Double
The standard deviation 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 2.
Remarks

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

LaTeX equation

where

LaTeX equation

is the LaTeX equation central moment of order LaTeX equation.

If adjustForBias is set to false, then the standard deviation is estimated through the coefficient

LaTeX equation

where

LaTeX equation

is the sample central moment of order LaTeX equation, LaTeX equation is the data length and

LaTeX equation

Such estimator is biased. If adjustForBias is set to true, then the variance estimator is corrected for bias and the standard deviation is evaluated through the coefficient

LaTeX equation

Examples

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

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class StandardDeviationExample1  
    {
        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);

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

            // Compute the data standard deviation.
            var stdDev = Stat.StandardDeviation(matrix, adjustForBias);

            Console.WriteLine();
            Console.WriteLine("Data standard deviation is:");
            Console.WriteLine(stdDev);

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

            Console.WriteLine();
            Console.WriteLine("Using read-only data. The standard deviation is:");
            Console.WriteLine(stdDevOfReadOnlyData);
        }
    }
}

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

See Also