FUNCTION
Correlation
Calculates the correlation of a given set of data.
Interface
#include <codecogs/statistics/moments/correlation.h>
using namespace Statistics::Moments;
The correlation coefficient provides a normalized view of correlation based on covariance:
(1)
where
= variance of a set of data and
= covariance of a set of data
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 , 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.278132Parameters
data1
the actual population data given as the second array
Returns
the correlation of the given set of data
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.