Click or drag to resize

StatSumOfSquaredDeviations Method (DoubleMatrix)

Returns the sum of squared deviations of the specified data.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static double SumOfSquaredDeviations(
	DoubleMatrix data
)

Parameters

data
Type: Novacta.AnalyticsDoubleMatrix
The data.

Return Value

Type: Double
The sum of squared deviations of the specified data.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
Remarks

This method returns the sum of squared deviations of data entries from their arithmetic mean. Let us define

LaTeX equation

where LaTeX equation is the data length. Then the returned value can be represented by the expression

LaTeX equation

where

LaTeX equation

is the data arithmetic mean.

Examples

In the following example, the sum of squared deviations of a data matrix is computed.

C#
using System;

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

            // Compute the data sum of squared deviations.
            var sumOfSquaredDevs = Stat.SumOfSquaredDeviations(matrix);

            Console.WriteLine();
            Console.WriteLine("Data sum of squared deviations is:");
            Console.WriteLine(sumOfSquaredDevs);

            // SumOfSquaredDeviations is overloaded to accept data as a read-only matrix:
            // compute the sum of squared deviations using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var sumOfSquaredDevsOfReadOnlyData = Stat.SumOfSquaredDeviations(readOnlyMatrix);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. The sum of squared deviations is:");
            Console.WriteLine(sumOfSquaredDevsOfReadOnlyData);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                
// 2                3                
// 3                4                
// 
// 
// 
// Data sum of squared deviations is:
// 5.5
// 
// Using read-only data. The sum of squared deviations is:
// 5.5

See Also