Recover Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttp://yahoo.com/
get GPL
COST (GBP)
this unit 0.30
sub units 0.00
add licence
0

Correlation

viewed 3359 times and licensed 194 times
Calculates the correlation of a given set of data.
Controller: CodeCogs

buy now get GPL add to cart

Interface

C++

Correlation

 
template<class T>doublecorrelationint n1
T*data0
T*data1 )[inline]
The correlation coefficient provides a normalized view of correlation based on covariance:

where
  • var(X) = variance of a set of data and
  • cov(X,Y) = covariance of a set of data
  • corr(X,Y) ranges from -1 (for negatively correlated variables) through zero (for uncorrelated variables) to +1
(for positively correlated variables).

While if X and Y are independent we have corr(x,y)=0, the latter does not imply the former.

References:

PlanetMath, http:planetmath.org/encyclopedia/Covariance.html

Example 1

#include <codecogs/statistics/moments/correlation.h>
#include <iostream>
int main()
{
  int x[4] = {3 , 7 , 5 , 6 };
  int y[4] = {4 , 3 , 7 , 1 };
  double corr = Stats::Moments::correlation<int>(4, x , y);
  std::cout << "The correlation of x and y is: " << corr << std::endl;
  return 0;
}
Output:
The correlation of x and y is: -0.278132

Parameters

data1the actual population data given as the second array

Returns

the correlation of the given set of data

Authors

Anca Filibiu (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


 

Page Comments

 
 Format Excel Equations

  You must login to leave a messge