Exercise

# Manual computation of correlation coefficients (1)

In order to get acquainted with the concept of correlation coefficients, it is a good idea to manually calculate the coefficients step by step in R. The general formula for calculating the correlation coefficient between two variables is $$ r = \frac{cov(A,B)}{s_A \cdot s_B}, $$ where \(cov(A,B)\) is the covariance between \(A\) and \(B\), while \(s_A\) and \(s_B\) are the standard deviations.

Instructions

**100 XP**

- The vectors
`A`

and`B`

have already been loaded into your workspace. Begin by calculating the**covariance**\(cov(A,B)\) between these vectors. Save all necessary intermediate values in new variables to simplify the computations. - First you have to compute the
**differences**of each vector element with the mean and save them in the new variables`diff_A`

and`diff_B`

. Use the`mean()`

function to do this. - Then,
**calculate**the covariance between`A`

and`B`

using your new variables. Save your result in the variable`cov`

.