Edited by Caidoz, Dvortygirl, Chris Hadley, Lucky7 and 28 others
Spearman's rank correlation coefficient allows you to identify whether two variables relate in a monotonic function (i.e., that when one number increases, so does the other, or vice-versa). Follow this simple guide to make your calculation by hand, or for instructions on how to compute the correlation coefficient in Excel or R.
- 1Draw your data table. This will organize the information you need to calculate Spearman's Rank Correlation Coefficient. You will need:
- 6 Columns, with headers as shown below.
- As many rows as you have pairs of data.
- 2Fill in the first two columns with your pairs of data
- 3In your third column rank the data in your first column from 1 to n (the number of data you have). Give the lowest number a rank of 1, the next lowest number a rank of 2, and so on.
- 4In your fourth column do the same as in step 3, but instead rank the second column.
In the example at right, there are two 5s that would otherwise have ranks of 2 and 3. Since there are two 5s, take the mean of their ranks. The mean of 2 and 3 is 2.5, so assign the rank 2.5 to both 5s.
- 5In the "d" column calculate the difference between the two numbers in each pair of ranks. That is, if one is ranked 1 and the other 3 the difference would be 2. (The sign doesn't matter, since the next step is to square this number.)
- 7Square each of the numbers in the "d" column and write these values in the "d2" column.
- 8Add up all the data in the "d2" column. This value is Σd2.
- 9Insert this value into the Spearman's Rank Correlation Coefficient formula.
- 10Replace the "n"'s with the number of pairs of data you have and calculate the answer.
- 11Interpret your result. It can vary between -1 and 1.
- Close to -1 - Negative correlation.
- Close to 0 - No linear correlation.
- Close to 1 - Positive correlation.
- 1Create a new columns with the ranks of your existing columns. For example if your data is in Column A2:A11, you want to use the formula "=RANK(A2,A$2:A$11)", and copy it down and across for all your rows and columns.
- 2In a new cell, do a correlation between the two rank columns with something like "=CORREL(C2:C11,D2:D11)". In this case, C and D would correspond to the rank columns. The correlation cell will have your Spearman's Rank Correlation.
- 1Get R if you don't already have it
- 2Save your data as a CSV file with the data you want to correlate in the first two columns. You can typically do this through the "Save as" menu.
- 3Open the R editor. If you are on the terminal, simply run R. From the desktop, you want to click on the R logo.
- 4Type the commands:
- d <- read.csv("NAME_OF_YOUR_CSV.csv") and hit enter
- Most data sets should contain at least 5 pairs of data in order to identify a trend (3 were used for the example to make it easier to demonstrate).
- Spearman's rank correlation coefficient will only identify the strength of correlation where the data is consistently increasing or decreasing. If a scatter graph of the data any other trend Spearman's rank will not give an accurate representation of its correlation.
- This formula is based on the assumption that there are no ties. When there are ties such as in the example one should use the definition: the product moment correlation coefficient based on the ranks.
Edit Related wikiHows
Categories: Probability and Statistics
Recent edits by: Allie, Jacob, Genius_knight