Project 8: Correlation Coefficient

We are often interested in whether two variables are related (have an association).  For example, vitamin C intake and length of a cold: Do people generally get over a cold quicker if they consume vitamin C while they are sick?  

The above scatterplot: How closely related were the students' third exam scores with their final exam scores?  We could look at the scatterplot above and get an idea that generally students who did better on the third exam also did better on the final exam.

To help answer these questions, we use a statistical measure called the correlation coefficient.  Pearson's Correlation Coefficient (R) measures the strength and direction of the linear relationship between X and Y.

Project 8: Arrays 'x' and 'y' have been initialized.  There are also working methods available called getAverage and getSD.

x is an array that holds the x-values (independent variable)

y is an array that holds the y-values (dependent variable)

getAverage(a) returns the average of array 'a'.

getSD(a) returns the average of array 'a'.

Task: Appropriately initialize the value of 'r' which represents the correlation coefficient between x and y.

Example:

x = [3, 5, 6];

y = [1,4, 4];

getAverage(x) returns 4.666

getAverage(y) returns 3.000

getSD(x) returns 1.5275

getSD(y) returns 1.732

The calculation and value for 'r' is shown below.

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0