Click or drag to resize
sqx

SQXCorrelationMatrix Method

Procedure CorrelationMatrix [nvarchar](max) @Query, [bit] @Population, [bit] @SnapShot, [Matrix] @CorrelationMatrix OUTPUT

Namespace:  sqx
Assembly:  SQX (in SQX.dll) Version: 1.0.2.6 (1.0.2.6)
Syntax
C#
public static int CorrelationMatrix(
	SqlChars Query,
	SqlBoolean Population,
	SqlBoolean SnapShot,
	out Matrix CorrelationMatrix
)

Parameters

Query
Type: System.Data.SqlTypesSqlChars
[nvarchar](max)
Population
Type: System.Data.SqlTypesSqlBoolean
[bit]
SnapShot
Type: System.Data.SqlTypesSqlBoolean
[bit] 0 Read Commited | 1 SnapShot
CorrelationMatrix
Type: sqxMatrix
[Matrix] Output

Return Value

Type: Int32
[int] 0 success | -1 failure
Remarks
High performance Correlation Matrix procedure.
It can compute Correlation Matrix up to 91 Columns.

NOTE: Query must return a dataset with only the matrix columns with numeric data type.
NOTE: CTE not available in @Query parameter.
Examples
SQL
declare @Query nvarchar(max) = N'
select a.Value [1],b.Value [2],c.Value [3]
from sqx.VectorTable(sqx.RandomVector(10,1)) a
inner join sqx.VectorTable(sqx.RandomVector(10,2)) b ON a.ID = b.ID
inner join sqx.VectorTable(sqx.RandomVector(10,3)) c ON a.ID = c.ID
'
declare @R sqx.Matrix
exec sqx.CorrelationMatrix @Query = @Query
    , @Population = 1, @SnapShot = 0, @CorrelationMatrix = @R OUTPUT
exec sqx.MatrixToTable @R
/*
ID          1                      2                      3
----------- ---------------------- ---------------------- ----------------------
1           1                      0.0171373794175597     0.258705024392653
2           0.0171373794175597     1                      -0.394987971874921
3           0.258705024392653      -0.394987971874921     1*/
See Also