﻿ Measures.Correlation Method (Double[,])

Calculates the correlation matrix for a matrix of samples.

Namespace:  Accord.Statistics
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
```public static double[,] Correlation(
this double[,] matrix
)```

#### Parameters

matrix
Type: SystemDouble
A multi-dimensional array containing the matrix values.

#### Return Value

Type: Double
The correlation matrix.

#### Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
In statistics and probability theory, the correlation matrix is the same as the covariance matrix of the standardized random variables.
Examples
```// Let's say we have a matrix containing 5
// samples (rows) of 3 dimensions (columns):
double[,] matrix = new double[,]
{
{ 4.0, 2.0, 0.60 },
{ 4.2, 2.1, 0.59 },
{ 3.9, 2.0, 0.58 },
{ 4.3, 2.1, 0.62 },
{ 4.1, 2.2, 0.63 }
};

// We can compute their correlation matrix using
double[,] corr1 = Measures.Correlation(matrix);

// The matrix should be equal to:
double[,] expected = new double[,]
{
{ 1.000000, 0.5669467, 0.533745 },
{ 0.566946, 1.0000000, 0.778127 },
{ 0.533745, 0.7781271, 1.000000 }
};

// The same could be repeated with a jagged matrix instead:
double[][] jagged = new double[][]
{
new double[] { 4.0, 2.0, 0.60 },
new double[] { 4.2, 2.1, 0.59 },
new double[] { 3.9, 2.0, 0.58 },
new double[] { 4.3, 2.1, 0.62 },
new double[] { 4.1, 2.2, 0.63 }
};

// And the value would be the same:
double[][] corr2 = Measures.Correlation(jagged);```
Examples
```// Let's say we have a matrix containing 5
// samples (rows) of 3 dimensions (columns):
double[,] matrix = new double[,]
{
{ 4.0, 2.0, 0.60 },
{ 4.2, 2.1, 0.59 },
{ 3.9, 2.0, 0.58 },
{ 4.3, 2.1, 0.62 },
{ 4.1, 2.2, 0.63 }
};

// We can compute their correlation matrix using
double[,] corr1 = Measures.Correlation(matrix);

// The matrix should be equal to:
double[,] expected = new double[,]
{
{ 1.000000, 0.5669467, 0.533745 },
{ 0.566946, 1.0000000, 0.778127 },
{ 0.533745, 0.7781271, 1.000000 }
};

// The same could be repeated with a jagged matrix instead:
double[][] jagged = new double[][]
{
new double[] { 4.0, 2.0, 0.60 },
new double[] { 4.2, 2.1, 0.59 },
new double[] { 3.9, 2.0, 0.58 },
new double[] { 4.3, 2.1, 0.62 },
new double[] { 4.1, 2.2, 0.63 }
};

// And the value would be the same:
double[][] corr2 = Measures.Correlation(jagged);```