Pearson correlation measures the strength and direction of a straight-line (linear) relationship between two continuous variables.
Click to reveal answer
beginner
What is Spearman correlation used for?
Spearman correlation measures the strength and direction of a monotonic relationship between two variables using their ranks, not the raw data values.
Click to reveal answer
intermediate
When should you use Spearman correlation instead of Pearson?
Use Spearman when data is not normally distributed, has outliers, or the relationship is not linear but still monotonic (always increasing or decreasing).
Click to reveal answer
beginner
What is the range of correlation coefficients for both Pearson and Spearman?
Both Pearson and Spearman correlation coefficients range from -1 to 1, where -1 means perfect negative correlation, 0 means no correlation, and 1 means perfect positive correlation.
Click to reveal answer
beginner
How do you interpret a correlation coefficient of 0.8?
A correlation of 0.8 means a strong positive relationship: as one variable increases, the other tends to increase as well.
Click to reveal answer
Which correlation method is best for measuring linear relationships?
ASpearman
BKendall
CPearson
DChi-square
✗ Incorrect
Pearson correlation measures linear relationships between continuous variables.
Spearman correlation uses which of the following to calculate correlation?
ARanks of data
BCategorical labels
CRaw data values
DMean values
✗ Incorrect
Spearman correlation uses ranks of the data to measure monotonic relationships.
What does a correlation coefficient of 0 indicate?
APerfect negative correlation
BNo correlation
CPerfect positive correlation
DMonotonic relationship
✗ Incorrect
A coefficient of 0 means no linear or monotonic relationship between variables.
Which correlation is more robust to outliers?
ANeither
BPearson
CBoth are equally sensitive
DSpearman
✗ Incorrect
Spearman correlation is less affected by outliers because it uses ranks.
If data is not normally distributed, which correlation should you prefer?
ASpearman
BNone
CBoth are fine
DPearson
✗ Incorrect
Spearman correlation does not assume normal distribution and is better for non-normal data.
Explain the difference between Pearson and Spearman correlation in simple terms.
Think about how each method treats the data and what kind of relationships they detect.
You got /5 concepts.
Describe a real-life example where Spearman correlation is more appropriate than Pearson.
Consider situations where data is not perfectly straight but still ordered.
You got /4 concepts.
Practice
(1/5)
1. What does the Pearson correlation coefficient measure between two variables?
easy
A. The rank order similarity between two variables
B. The difference in means between two groups
C. The strength and direction of a linear relationship
D. The frequency distribution of a variable
Solution
Step 1: Understand Pearson correlation concept
Pearson correlation measures how strongly two variables move together in a straight line.
Step 2: Differentiate from other measures
Unlike Spearman, Pearson focuses on linear relationships, not ranks or means.
Final Answer:
The strength and direction of a linear relationship -> Option C
Assuming Pearson works for non-linear relationships
2. Which of the following Python code snippets correctly calculates the Spearman correlation between two pandas Series x and y?
easy
A. x.corr(y, method='spearman')
B. x.corr(y, method='pearson')
C. spearmanr(x, y)
D. corr(x, y, method='spearman')
Solution
Step 1: Recall pandas correlation syntax
In pandas, Series.corr() accepts a method argument with values like 'pearson' or 'spearman'.
Step 2: Identify correct method call
x.corr(y, method='spearman') uses x.corr(y, method='spearman'), which is the correct pandas syntax.
Final Answer:
x.corr(y, method='spearman') -> Option A
Quick Check:
pandas Series.corr with method='spearman' [OK]
Hint: Use Series.corr with method='spearman' for Spearman correlation [OK]
Common Mistakes:
Using 'pearson' instead of 'spearman' for Spearman correlation
Calling a non-existent function like corr() standalone
Confusing scipy's spearmanr with pandas syntax
3. Given the following code, what is the output of print(round(corr, 2))?
import pandas as pd
x = pd.Series([1, 2, 3, 4, 5])
y = pd.Series([5, 6, 7, 8, 8])
corr = x.corr(y, method='pearson')
medium
A. 0.75
B. 0.90
C. 0.85
D. 0.97
Solution
Step 1: Calculate Pearson correlation manually
Calculate covariance and standard deviations of x and y, then compute correlation.
Here, x and y increase mostly together, so correlation is high.
Step 2: Use pandas to confirm
Running the code gives approximately 0.9746, which rounds to 0.97.
Final Answer:
0.97 -> Option D
Quick Check:
pandas Pearson correlation ≈ 0.97 [OK]
Hint: Use pandas corr() to get exact correlation quickly [OK]
Common Mistakes:
Confusing Pearson with Spearman correlation values
Rounding incorrectly or too early
Assuming correlation must be exactly 1 for similar sequences
4. Identify the error in this code snippet that attempts to calculate Spearman correlation:
from scipy.stats import spearmanr
x = [1, 2, 3, 4]
y = [4, 3, 2, 1]
result = spearmanr(x, y)
print(result.correlation)
medium
A. The function spearmanr requires numpy arrays, not lists
B. The attribute 'correlation' does not exist in the result object
C. The print statement should be inside a function
D. The import statement is incorrect
Solution
Step 1: Check spearmanr return type
spearmanr returns a namedtuple SpearmanRResult with fields statistic (Spearman correlation coefficient) and pvalue.
Step 2: Confirm attribute access
The code accesses result.correlation, but no such attribute exists. Use result.statistic instead.
Final Answer:
The attribute 'correlation' does not exist in the result object -> Option B
Quick Check:
spearmanr uses result.statistic [OK]
Hint: Use result.statistic for spearmanr correlation [OK]
Common Mistakes:
Assuming lists cannot be used with spearmanr
Misunderstanding the return type of spearmanr
Incorrect import or syntax errors
5. You have two variables: age (numeric) and education_level (ordinal ranks: 1=High School, 2=Bachelor, 3=Master, 4=PhD). Which correlation method is most appropriate to measure their association and why?
hard
A. Spearman, because education_level is ordinal and relationship may be monotonic
B. Pearson, because it handles ordinal data better
C. Neither, because correlation cannot be calculated between these variables
D. Pearson, because both are numeric variables
Solution
Step 1: Identify variable types
Age is numeric continuous; education_level is ordinal categorical (ranked).
Step 2: Choose correlation method
Spearman correlation is best for ordinal data and monotonic relationships, unlike Pearson which assumes linear and interval data.
Final Answer:
Spearman, because education_level is ordinal and relationship may be monotonic -> Option A
Quick Check:
Ordinal data + monotonic = Spearman [OK]
Hint: Use Spearman for ordinal or ranked data [OK]
Common Mistakes:
Using Pearson for ordinal data incorrectly
Thinking correlation can't be done with ordinal variables
Confusing monotonic with linear relationships
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.