Which statement correctly describes the Pearson correlation coefficient between two variables?
Think about what correlation tells us about two variables' relationship.
The Pearson correlation coefficient quantifies how strongly two continuous variables move together in a linear way, ranging from -1 to 1.
What is the output of the following Python code?
import numpy as np x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 4, 6, 8, 10]) correlation = np.corrcoef(x, y)[0, 1] print(round(correlation, 2))
Check if y is a perfect linear multiple of x.
Since y is exactly 2 times x, the correlation is perfect positive, which is 1.00.
You have two variables with a clear nonlinear but monotonic relationship. Which correlation method is best to measure their association?
Consider a method that uses ranks instead of raw values.
Spearman correlation measures monotonic relationships by ranking data, so it works well for nonlinear but monotonic associations.
Given the correlation matrix below, how many pairs of variables have a strong positive correlation (above 0.7)?
A B C D A 1.0 0.8 0.3 0.6 B 0.8 1.0 0.5 0.9 C 0.3 0.5 1.0 0.2 D 0.6 0.9 0.2 1.0
Count pairs ignoring the diagonal and duplicates.
Pairs with correlation above 0.7 are (A,B)=0.8 and (B,D)=0.9, total 2 pairs. Ignore the diagonal and symmetric duplicates.
What error does the following Python code raise?
import numpy as np x = [1, 2, 3] y = [4, 5] correlation = np.corrcoef(x, y)[0, 1] print(correlation)
Check if input arrays must have the same length.
np.corrcoef requires inputs of the same length; different lengths cause a ValueError.
