Statistics.CorrCoef Method

Overload List

#SignatureDescription
1void CorrCoef(TDenseMtxVec X, TDenseMtxVec Y, TMtx aResult)Pearson correlation coefficients.
2void CorrCoef(TDenseMtxVec X, TDenseMtxVec Y, TMtx aResult, ref Double tValue)Pearson correlation coefficients.
3void CorrCoef(TMtx X, TMtx aResult)Pearson correlation coefficients between matrix rows and cols.

Overload 1: void CorrCoef(TDenseMtxVec X, TDenseMtxVec Y, TMtx aResult)

Pearson correlation coefficients.

#NameDescription
1XDefines first sample (variable) values (observables).
2YDefines second sample (variable) values (observables).
3aResultReturns Pearson correlation coefficients bewteen samples X and Y. Size of Result is adjusted automatically.

Result: stored in self (calling object)

Remarks:

Correlation coefficient

The correlation coefficient rho between two random variables is defined by the following equation:

ρ(x,y)=Cov(x,y)σxσy=E(xy)E(x)E(y)E(x2)E(x)2E(y2)E(y)2.\rho_{(x,y)} = \cfrac{\text{Cov}(x,y)}{\sigma_x \sigma_y} = \cfrac{E (x y)-E(x) E(y)}{\sqrt{E(x^2)-E(x)^2}\sqrt{E(y^2)-E(y)^2}}\qquad .

where x,y are two variables, Cov covariance betwen x and y, sigma(s) their expected standard deviations and E-s their expected values. If the variables are independent then the correlation is 0, but the converse is not true because the correlation coefficient detects only linear dependencies between two variables.

Sample correlation coefficients.

If we have a series of n measurements of X and Y, then the Pearson product-moment correlation coefficient can be used to estimate the correlation of X and Y. The Pearson coefficient is also known as the "sample correlation coefficient". The Pearson correlation coefficient is then the best estimate of the correlation of X and Y .

Examples
using Dew.Math;
using Dew.Stats.Units;
namespace Dew.Examples
{
    private void Example()
    {
        Vector data1 = new Vector(0);
        Vector data2 = new Vector(0);
        Matrix corr = new Matrix(0,0);
        data1.SetIt(false, new double[] {1,2,3});
        data2.SetIt(false, new double[] {5, 5.5, 1.0} );
        Statistics.CorrCoef(data1,data2,corr);
        // corr = [1.00000000, -0.81088485,
        //            -0.81088485,  1.00000000]
    }
}

Overload 2: void CorrCoef(TDenseMtxVec X, TDenseMtxVec Y, TMtx aResult, ref Double tValue)

Pearson correlation coefficients.

#NameTypeDescription
1XTDenseMtxVecsource TVec or TMtx
2YTDenseMtxVecsource TVec or TMtx
3aResultTMtxsource TMtx
4tValueDouble (ref)output

Result: stored in self (calling object)

Remarks:

Additionally returns also the Students t-distribution value as an indicator of statistical significance.

Overload 3: void CorrCoef(TMtx X, TMtx aResult)

Pearson correlation coefficients between matrix rows and cols.

#NameTypeDescription
1XTMtxsource TMtx
2aResultTMtxsource TMtx

Result: stored in self (calling object)

Remarks:

This version calculates Pearson correlation coefficients rx,y between X matrix rows and cols. X colums are treated as samples (variables) and rows as values (observables).