Pearson and Spearman Correlation: When the Same Data Tells Two Stories
A takeaway counter shows that there are 6 busy periods. Orders increase by 10s from 10 to 60. The average customer waiting times (in minutes) are 2, 4, 6, 8, 10 and 40.
These are indicative numbers, but they reveal an analytical issue. As the previous periods indicate, the last period has the highest number of orders and the longest wait. However, the last jump is bigger than the others. What is the level of the relationship?
When computing Pearson and Spearman correlation on this data set, one gets an answer of ~0.79 and the other 1.00. Both calculations are correct. They are measuring various aspects of the same 6 observations.
Distance is a factor for Pearson
Pearson's correlation coefficient, commonly denoted as r, is a numerical measure of the strength and direction of the linear relationship between two numerical variables. Its computation is based on the distance of each value from its mean, measured in standard deviations of the variables.
A value close to +1 means that the straight-line pattern is strong. Near -1 means a negative one; near zero means little linear association. Pearson may be computed on skewed data, but conventional significance test and confidence intervals may need further assumptions.
In the takeaway example, the waiting time is increasing by two minutes for every 10 additional orders. The sixth skip is 30 minutes. That point deviates the data from a straight line, and Pearson is approximately 0.79.
The outcome is not a good indicator of a forecast. There are only six observations, which is not enough to make confident operational decisions, and there is an unusual change that needs to be investigated.
Spearman looks at the order
Spearman's rank correlation, also known as rho or rₛ, first ranks the observations. Then it computes the correlation based on these ranks and not the original measurements.
Order counts 1-6 from worst to best. The rankings are the same in the two lists, therefore, Spearman gives +1.00. It detects a perfectly increasing monotonic relationship: higher values of one variable always accompany higher values of the other.
That's a more limited statement than it seems. Spearman does not state that the waiting time increases at a regular rate. A 10-minute and a 40-minute wait is a huge difference for the customer but only a difference in rank here.
Spearman is also useful for ordinal measurements, like survey responses from very dissatisfied to very satisfied. If values are tied, statistical software usually assigns average ranks, which should be dealt with appropriately and not ignored.
What should the result be that will inform the decision?
The restaurant manager wants to forecast if the next 10 orders will require two minutes or twenty minutes to be added to the queue. Spearman does not answer that: it forgets about the size of the increments. Pearson explains linear association, and a coefficient by itself is not enough to estimate waiting time. A scatter graph and a suitable model to predict would be required.
Spearman explicitly states the ordering if the question is whether the busier periods tend to be associated with longer waits. So a different operational question may warrant a different statistic.
Another reason to compare the methods is because of outliers. Pearson can vary significantly if an unusual observation is added to a small set of data. Spearman is generally less sensitive to the size of an extreme value, but is not completely resistant to influential data or measurement errors.
Never select the coefficient that gives the “showier” number. Select the one whose relationship is similar to the question.
Before posting the coefficient, plot the points
A scatterplot may reveal patterns that are not evident in the single coefficient. It is possible to have a strong Spearman correlation and a weaker Pearson value for a curved relationship. A U-shaped relationship (the outcome first decreases and then increases) can cause both coefficients to be spuriously small.
Ensure measurements are matched correctly, that missing measurements are dealt with consistently, and that the observations are independent. If the same outlet or customer is read multiple times, methods that take that structure into consideration may be necessary.
Lastly, correlation does not determine the cause of a pattern. Along with order volume, waiting times may be impacted by a staffing shortage or equipment failure or changes in order complexity.
The takeaway dataset contains two valid summaries: the ranks increase in perfect correlation, and the wait times do not follow a simple linear trend. A useful analysis reports the coefficient that answers its question, displays the plot, and elucidates what the number doesn't account for.