Code Challenges
- FizzBuzz
- Mean of a List
- Median of a List
- Variance of a List
- Standard Deviation of a List
- Sample Covariance
- Correlation Coefficient
- Simple Linear Regression
- Vector Dot Product
- Random Matrix

- Save
- Run All Cells
- Clear All Output
- Runtime
- Download
- Difficulty Rating
Loading Runtime
Create a function called correlation_coefficient.
This function will be passed two lists of numbers of equal length and should return the correlation coefficient of the two lists.
There are many ways to write the equation for the correlation coefficient r. If you have completed the Standard Deviation of a List code challenge as well as the Sample Covariance code challenge, then the following equation for the correlation coefficient of two variables (x and y) will be particularly useful:
Where:
ris the sample correlation coefficientCov(x,y)is the sample covariance of variablesxandys_xis the sample standard deviation ofxs_yis the sample standard deviation ofy
From this equation, we see that the correlation coefficient is equivalent to the covariance of the two variables divided by the product of their standard deviations.
Example:
correlation_coef([3,6,8,4,5,9], [8,5,3,0,4,3])
Returns: -0.2998310519154245