Exercise

# Nonparametric correlation

There are also non-parametric ways to measure for instance the association between variables. The most important of these is the Spearman rank correlation coefficient which is often treated as the non-parametric counterpart of the Pearson correlation coefficient.

The Spearman correlation coefficient is a good replacement of the Pearson correlation if one of these conditions applies to your variables:

- they are not numerical but one or both of the variables are ordinal
- they are not linearly related
- they contain one or more outliers or
- they don't follow a bivariate normal distribution or you cannot check this due to lack of data.

You can interpret the Spearman correlation in the same fashion as the Pearson correlation coefficients. a \(\rho\) of smaller than 0 denotes a negative relationship while a \(\rho\) of larger than 0 denotes a positive relationship. To calculate the correlation in R, you can work with the familiar `cor()`

function. This function accepts an `x`

and `y`

vector. Also, you can specify the correlation method in this function by using the `method`

parameter. By default this is set to "pearson". If you set it to "spearman", the function calculates the spearman correlation coefficient.

Instructions

**100 XP**

- In your console, a dataframe called
`beer_data`

is available which contains the frequency of craft beer consumption. This frame contains the variables`education_level`

which represents the highest completed education level of a respondee. 1 represents primary school, 2 high school, 3 bachelor, 4 master, 5 PhD. The variable`consumption`

represents the frequency with which the respondee consumes craft beer. 1 represents never, 2 rarely, 3 occassionally, 4 often and 5 very often. Calculate the Spearman correlation between education level and craft beer ratings and print this to the console.