Spearman’s correlation

Example RQ and data

RQ: Are people’s Likert scale ratings of their own activity levels associated with their self-rated self-esteem, also from a Likert scale?

Here’s what the first six rows of the data looks like:

selfesteem_data |> head()
  activity selfesteem
1        2          3
2        4          4
3        5          7
4        3          2
5        4          3
6        5          4


Here’s how we might plot this data (if you’re not sure what part of the code does, delete it or comment it out and try running what’s leftover to see what changes):

selfesteem_data |>
  mutate(
    activity = factor(activity),
    selfesteem = factor(selfesteem)
  ) |>
  ggplot(aes(x = activity, fill = selfesteem)) +
  geom_bar()

Define hypotheses

Our null hypothesis is that activity ratings and self-esteem ratings are not correlated—in other words, that they have a Spearman’s correlation \(r_S\) of 0.

Formally:

\[ H_0: r_S = 0 \]

# H0: r_S = 0

Our alternative hypothesis is that there is a correlation between activity ratings and self-esteem ratings. Formally:

\[ H_1: r_S ≠ 0 \]

# H1: r_S != 0

Run the test

To test whether Spearman’s correlation coefficient is significantly different from zero, we use the function cor.test() and give it the following arguments:

  • the first variable we want to compare
  • the second variable we want to compare
  • specify method = 'spearman' to make sure we’re doing Spearman’s correlation

(the order that you name the variables in does not matter for the test)

cor.test(
  selfesteem_data$activity,
  selfesteem_data$selfesteem,
  method = 'spearman'
)

    Spearman's rank correlation rho

data:  selfesteem_data$activity and selfesteem_data$selfesteem
S = 2063, p-value = 0.002
alternative hypothesis: true rho is not equal to 0
sample estimates:
    rho 
0.54097 

Note: If you get the following warning message, you can safely ignore it and just report your results as usual.

Warning message:
In cor.test.default(selfesteem_data$activity, selfesteem_data$selfesteem,  :
  cannot compute exact p-value with ties

Assumptions we must make

Type of constraint What to check for Spearman’s correlation
Data requirements Both variables represent rankings/orderings.

Data requirements

Both variables represent rankings/orderings.

If it makes sense to sort both variables into some kind of order, then you can consider them appropriate for Spearman’s correlation.

glimpse(selfesteem_data)
Rows: 30
Columns: 2
$ activity   <dbl> 2, 4, 5, 3, 4, 5, 6, 4, 7, 4, 5, 7, 4, 1, 6, 1, 5, 4, 5, 5,…
$ selfesteem <dbl> 3, 4, 7, 2, 3, 4, 4, 3, 6, 4, 4, 4, 3, 4, 7, 3, 5, 4, 5, 4,…

In this case, both activity and selfesteem are ratings from a Likert scale, so they are definitely ordinal variables.

Calculate effect size

The correlation coefficient itself is the effect size measure for correlations.

Interpreting any correlation coefficients:

  • Weak correlations: between .1 and .3 (whether positive or negative)
  • Moderate correlations: between .3 and .5 (whether positive or negative)
  • Strong correlations: greater than .5 (whether positive or negative)

Example write-up

Do people who rate their own activity levels higher also tend to have higher self-esteem? To analyse this, we used Spearman’s correlation to test the association between people’s activity level ratings (on a seven-point Likert scale) and their self-esteem ratings (also on a seven-point Likert scale). Spearman’s correlation is an appropriate choice because both variables are ordinal.

Specifically, we tested \(H_0: r_S = 0\) against \(H_1: r_S \neq 0\). We found a medium positive correlation that was significantly different from zero (\(r_S\) = .54, \(p\) = .002). We therefore reject the null hypothesis and conclude that activity rankings and self-esteem rankings are significantly positively associated.

TipReporting the results of a statistical test

The most important thing: Your decision about the null hypothesis should be clear.

You can make sure your decision is clear either by

  • stating that you reject/fail to reject H0, or
  • stating that the result is significant or not.