Statistics.CorrCoef Method

Overload List

#SignatureDescription
1procedure CorrCoef(const X: TDenseMtxVec; const Y: TDenseMtxVec; const aResult: TMtx);Pearson correlation coefficients.
2procedure CorrCoef(const X: TDenseMtxVec; const Y: TDenseMtxVec; const aResult: TMtx; var tValue: Double);Pearson correlation coefficients.
3procedure CorrCoef(const X: TMtx; const aResult: TMtx);Pearson correlation coefficients between matrix rows and cols.

Overload 1: procedure CorrCoef(const X: TDenseMtxVec; const Y: TDenseMtxVec; const aResult: TMtx);

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
Uses MtxExpr, Statistics;
procedure Example;
var Data1, Data2: Vector;
CorrMtx : Matrix;
begin
    Data1.SetIt(False,[1,2,3]);
    Data2.SetIt(False,[5,5.5,1]);
    CorrCoef(Data1,Data2,CorrMtx);
    // CorrMtx = [1.00000000, -0.81088485,
    //            -0.81088485,  1.00000000]
end;

Overload 2: procedure CorrCoef(const X: TDenseMtxVec; const Y: TDenseMtxVec; const aResult: TMtx; var tValue: Double);

Pearson correlation coefficients.

#NameTypeDescription
1XTDenseMtxVec
2YTDenseMtxVec
3aResultTMtx
4tValueDouble

Result: stored in self (calling object)

Remarks:

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

Overload 3: procedure CorrCoef(const X: TMtx; const aResult: TMtx);

Pearson correlation coefficients between matrix rows and cols.

#NameTypeDescription
1XTMtx
2aResultTMtx

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).