Click or drag to resize

StatSumOfSquaredDeviations Method (ReadOnlyDoubleMatrix, DataOperation)

Returns the sum of squared deviations of each row or column in the specified data.

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

Parameters

data
Type: Novacta.AnalyticsReadOnlyDoubleMatrix
The data.
dataOperation
Type: Novacta.AnalyticsDataOperation
A constant to specify if the sum of squared deviations is to be computed for rows or columns.

Return Value

Type: DoubleMatrix
The sum of squared deviations of each row or column in the specified data.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
ArgumentExceptiondataOperation is not a field of DataOperation.
Remarks

This method returns the sum of squared deviations of rows or columns of data from their arithmetic means. 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 sum of squared deviations of the i-th data row.

The sum of squared deviations of the i-th row can be represented by the expression

LaTeX equation

where

LaTeX equation

is the arithmetic mean of the i-th row.

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 sum of squared deviations of the j-th data column.

The sum of squared deviations of the j-th column can be represented by the expression

LaTeX equation

where

LaTeX equation

is the arithmetic mean of the j-th column.

Examples

In the following example, row and column sums of squared deviations in a data matrix are computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class SumOfSquaredDeviationsExample0  
    {
        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 sum of squared deviations on columns.
            var sumOfSquaredDevsOnColumns = Stat.SumOfSquaredDeviations(matrix, DataOperation.OnColumns);

            Console.WriteLine();
            Console.WriteLine("SumOfSquaredDeviations on columns:");
            Console.WriteLine(sumOfSquaredDevsOnColumns);

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

            Console.WriteLine();
            Console.WriteLine("SumOfSquaredDeviations on rows:");
            Console.WriteLine(sumOfSquaredDevsOnRows);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                
// 2                3                
// 3                4                
// 
// 
// 
// SumOfSquaredDeviations on columns:
// 2                2                
// 
// 
// 
// SumOfSquaredDeviations on rows:
// 0.5              
// 0.5              
// 0.5              
// 

See Also