FUNCTION
Pearson
Calculates the Pearson product for a given set of data.
Interface
#include <codecogs/statistics/moments/pearson.h>
using namespace Statistics::Moments;
Returns the Pearson product moment correlation coefficient, r, a dimensionless index that ranges from -1.0 to 1.0 inclusive and reflects the extent of a linear relationship between two data sets.
The formula for the Pearson product moment correlation coefficient, r, is:
(1)
where
and
are the sample mean.
Example 1
#include <codecogs/statistics/moments/pearson.h>
#include <iostream>
int main()
{
double x[5] = {4 , 5 , 8 , 6 , 3};
double y[5] = {6 , 7 , 8 , 3 , 2};
double rez = Stats::Moments::pearson<double>(5,x,y);
std::cout << "The Pearson product is: " << rez << std::endl;
return 0;
}Output:
The Pearson product is: 0.592494Parameters
N
the size of the array
data
is a set of independent values given as an array
data1
is a set of dependent values given as an array
Returns
returns the Pearson product moment correlation coefficient
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.