# Comparing two variables – Spearman’s rank-order correlation

Spearman’s rank-order correlation (often called Spearman’s ρ or rho) is a non-parametric test which measures the monotonic relationship between two ranked variables. This test is often used when Pearson product-moment correlation cannot be used because (one of) the assumptions for the test are challenged. Most of the time, the assumptions of normality and linearity will be a reason for not using Pearson’s product-moment correlation.

Spearman’s rho comes with one main assumption: the monotonicity of the relationship between variables. To better understand what monotonic relationship implies, check the following picture taken from Lærd statistics’ webpage:

As you may understand, as the first variable increases, the second variable must either increase or decrease in a monotonic manner, but not necessarily in a proportional manner.

Let’s check this with an example. Here we consider weather records for the last 12 months in Bergen. The variables are rain and temperature, and we’ll try to see whether there is a form of relationship between these variables.

Normality and equal variance are not to be check here, so let’s draw directly a scatter plot:

```rain<-c(38.2,171.1,83.2,94.8,107.2,87.6,116.0,253.0,262.6,99.8,189.0,93.8)
temperature<-c(5.6,8.1,10.7,13.6,15.8,12.9,9.4,6.6,5.5,0.6,1.8,4.3)
plot(rain~temperature)
```

Hard to see any obvious relationship…

Let’s check Spearman’s ρ . The function is `cor.test()`. Note that the function is the same as for Pearson’s and Kendall’s tau. The extra parameter `method=" "` defines which correlation coefficient is to be considered in the test (choose between `"pearson"`, `"spearman"` and `"kendall"`; if the parameter `method` is omitted, the default test will be Pearson’s r)

```cor.test(rain, temperature, method="spearman")
```

In this test, the null hypothesis H0 states that there is no relationship between the variables. Here, the p-value is largely greater than 0.05, this null hypothesis cannot be rejected.