Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

arson\'s Correlation Coefficient zyBooks catalog ) Help/FAQ You are given two ve

ID: 3881574 • Letter: A

Question

arson's Correlation Coefficient zyBooks catalog ) Help/FAQ You are given two vectors with three com- .ocnn.helan · computes the Pearson's correlation coefficle beiween theee wors Here is some explanation Pearson's correlation cofficient when applied to a sample is commonly represented by the letter r and may be referred to as the sample correlation coefficient or the sample Pearson correlation coefficient. We can obtain a formula for r by substituting estimates of the covariances and variances based on a sample into the formula above. So if we have one dataset (containing n values and another dataset i Vnl containing n values then that formula for r is n the lomx1,x2,x3 and yl.y2y3. Your goal is to implement a program that where . n is the sample size · z, , Vi are the single samples indexed with i +2= n>_A(the sample mean); and analogously for j Read input from the keyboard using the scarf function expecting inputs in the flowing format wdNddSd%dSd . the first three elements being x1, x2, x3 Output only the result strictly using the following format(he coefficient) · ACTINTY 13.6.1. Pearsonis Correlation Coefficient 5/35 pearson.c Load default template ,include «math.h» 4double getContf Cint xi, int x2, int x3, int yi, int y2, int y3)i Peron's orrelation coefficient 6//Donoemodify the tr, finction int maino - Declaretions 9 int xi,2,x3.yl,y2,y3 double coeff 12 Reads inputs 15 1 Conputes coefficient 1 Displays output return z2 1 24 double getcoeff Cint xi, int x2, int x3, ne yi, int y, ine y3) f

Explanation / Answer

double getCoeff(int x1,int x2,int x3,int y1,int y1,int y2,int y3)
{
double coeff=0.0,meanx=0.0,meany=0.0,covariance=0.0,variancex=0.0,variancey=0.0,product=0.0;
meanx=(double)(x1+x2+x3)/(double)3;
meany=(double)(y1+y2+y3)/(double)3;
//calculate covariance
covariance=(x1-meanx)*(y1-meany)+(x2-meanx)*(y2-meany)+(x3-meanx)*(y3-meany);
//calculate variance
variancex=(x1-meanx)*(x1-meanx)+(x2-meanx)*(x2-meanx)+(x3-meanx)*(x3-meanx);
variancey=(y1-meany)*(y1-meany)+(y2-meany)*(y2-meany)+(y3-meany)*(y3-meany);
product=sqrt(variancex)*sqrt(variancey);
coeff=covariance/product;
return coeff;   
}