You are here: Symbol Reference > Dew.Stats Namespace > Statistics Class > Statistics Methods > CorrCoef Method > CorrCoef Method (TDenseMtxVec, TDenseMtxVec, TMtx)
Dew Stats for .NET
Contents
PreviousUpNext
Statistics.CorrCoef Method (TDenseMtxVec, TDenseMtxVec, TMtx)

Pearson correlation coefficients.

C#
public CorrCoef(TDenseMtxVec X, TDenseMtxVec Y, TMtx Result);
Parameters
Parameters 
Description 
Defines first sample (variable) values (observables). 
Defines second sample (variable) values (observables). 
Result 
Returns Pearson correlation coefficients bewteen samplex X and Y. Size of Result is adjusted automatically. 

Calculates Person correlation coefficients between X and Y representing two samples/variables with X and Y Values being treated as observables. 

If X and Y are two matrices, the rouitine calculates Pearson correlation coefficients rx,y between X and Y matrix. The algorithm assumes X and Y are two samples (variables) and all X are are treated as it's observables (same goes for Y). 

Correlation coefficient 

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

 

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 .

The correlation is defined only if both of the standard deviations are finite and both of them are nonzero.

Calculate correlation coefficients from Data1 and Data2 representing two variables.

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.CorrCoeff(data1,data2,corr);
    // corr = [1.00000000, -0.81088485,
    //            -0.81088485,  1.00000000]
  }
}
What do you think about this topic? Send feedback!
Copyright (c) 1999-2010 by Dew Research. All rights reserved.