Pearson Correlation Coefficient

When exploring relationships between two continuous variables, a scatter plot provides a visual overview. To quantify the strength and direction of a linear relationship, we turn to the Pearson correlation coefficient, often denoted as rr. This metric is the most widely used measure of correlation in statistics and data science, providing a single, interpretable number that summarizes how two variables move together.

Defining Pearson's r

The Pearson correlation coefficient, also known as Pearson's rr, measures the linear relationship between two continuous variables, XX and YY. Its value ranges from -1 to +1. A value of +1 indicates a perfect positive linear relationship, meaning as XX increases, YY increases proportionally. A value of -1 signifies a perfect negative linear relationship, where as XX increases, YY decreases proportionally. A value of 0 suggests no linear relationship between the variables.

📐 Pearson's r Formula

The Pearson correlation coefficient is calculated as the covariance of the two variables divided by the product of their standard deviations:

rXY=Cov(X,Y)σXσYr_{XY} = \frac{Cov(X, Y)}{\sigma_X \sigma_Y}

Where:
- Cov(X,Y)Cov(X, Y) is the covariance between XX and YY.
- σX\sigma_X is the standard deviation of XX.
- σY\sigma_Y is the standard deviation of YY.

This normalization ensures that rr is a unitless measure, always falling between -1 and +1.

Calculating Pearson's r Manually

To understand how Pearson's rr works, consider its components. The numerator, covariance, indicates the direction of the linear relationship (positive or negative) and its unnormalized strength. The denominator, the product of standard deviations, scales this covariance, effectively removing the units and bounding the result between -1 and +1. This normalization allows for direct comparison of correlation strength across different datasets and units.

pythonStep-by-Step Calculation of Pearson's r

Properties and Assumptions

Pearson's rr possesses several important properties. It is symmetric, meaning the correlation between XX and YY is the same as between YY and XX (rXY=rYXr_{XY} = r_{YX}). It is also scale-invariant and location-invariant, which means changing the units of measurement (e.g., from meters to centimeters) or adding a constant to all values in a variable will not change the correlation coefficient. However, Pearson's rr is sensitive to outliers, which can significantly distort its value.

Check Your Understanding
If we convert exam scores from points to percentages, how would Pearson's r with hours studied change?

For Pearson's rr to be a reliable and interpretable measure, several assumptions about the data should ideally be met. The most critical assumption is that the relationship between the variables is linear. If the true relationship is non-linear (e.g., parabolic or exponential), Pearson's rr may be close to zero even if a strong relationship exists. Other assumptions include that the variables are continuous and approximately normally distributed (especially for hypothesis testing), and that there are no significant outliers distorting the linear pattern.

Key Assumptions of Pearson Correlation
AssumptionWhy it Matters
LinearityThe relationship between variables must be linear.
Continuous VariablesBoth variables should be measured on an interval or ratio scale.
No Significant OutliersExtreme values should not disproportionately influence the coefficient.
HomoscedasticityThe variance of residuals (errors) should be consistent across all levels of the independent variable.
Normality (for inference)Variables are approximately normally distributed (especially for small samples).
Understanding these assumptions helps determine when Pearson's r is an appropriate and reliable measure.

Interpreting the Coefficient

Interpreting Pearson's rr involves considering both its sign and its magnitude. The sign (+ or -) indicates the direction of the relationship: positive means both variables increase or decrease together, while negative means one increases as the other decreases. The magnitude (absolute value) indicates the strength of the linear relationship. A common guideline suggests that r|r| values between 0.1 and 0.3 indicate a weak correlation, 0.3 to 0.5 a moderate correlation, and above 0.5 a strong correlation. Remember, correlation does not imply causation; it only describes an association.

pythonUsing SciPy for Pearson Correlation and P-value

Visualizing Different Linear Relationships

Scatter plots are essential for visually confirming the linearity of a relationship and for identifying potential outliers. While Pearson's rr provides a numerical summary, a scatter plot reveals the underlying data pattern. Different values of rr correspond to distinct visual patterns on a scatter plot, from tightly clustered points forming a line (strong correlation) to widely dispersed points with no discernible trend (weak or no correlation).

Pearson's r and Scatter Plot Patterns
This scatter plot shows three distinct datasets, each illustrating a different Pearson correlation coefficient. The 'Strong Positive' group shows points tightly clustered along an upward-sloping line, indicating a high positive 'r'. The 'Weak Negative' group shows a general downward trend, but with more scatter, reflecting a moderate negative 'r'. The 'No Correlation' group displays points randomly scattered, resulting in an 'r' close to zero.
Loading chart...
Key Insight: The visual pattern on a scatter plot directly corresponds to the magnitude and sign of Pearson's r, but also reveals non-linearities or outliers that the coefficient alone might miss.

Limitations and Misinterpretations

While powerful, Pearson's rr has limitations. It is strictly a measure of linear association. A low rr value does not mean there is no relationship, only that there is no linear relationship. Strong non-linear associations might yield a Pearson's rr close to zero. Additionally, Pearson's rr is highly susceptible to outliers, which can dramatically alter its value and lead to incorrect conclusions. Always visualize your data with a scatter plot before interpreting the correlation coefficient.

pythonPearson's r with Non-Linear Data and Outliers
Check Your Understanding
If Pearson's r is near zero, what can we conclude about the relationship between two variables?

When to Use Pearson's r

Pearson's rr is the go-to metric when you need to quantify the strength and direction of a linear association between two continuous variables. It is widely used in initial data exploration to identify potential linear dependencies, in feature selection for machine learning models (especially linear models), and in hypothesis testing to determine if a linear relationship is statistically significant. Always pair its calculation with a scatter plot to visually validate the linearity assumption and check for outliers.

Try It Yourself
Calculate Pearson's r for the provided dataset of 'temperature' and 'ice_cream_sales'. Interpret the result, including its strength and direction, and comment on its statistical significance.
python
Key Takeaways
  • Pearson's rr quantifies the strength and direction of linear relationships between two continuous variables, ranging from -1 to +1.

  • A value of +1 indicates a perfect positive linear correlation, -1 a perfect negative, and 0 no linear correlation.

  • The coefficient is calculated as the covariance divided by the product of standard deviations, making it unitless and bounded.

  • Pearson's rr is symmetric, scale-invariant, and location-invariant, but highly sensitive to outliers.

  • It assumes a linear relationship; a low rr does not rule out strong non-linear associations.

  • Always visualize data with a scatter plot to confirm linearity and detect outliers before interpreting Pearson's rr.

Ready to keep this from fading?

Bitelrn turns lessons like this into a full course — quizzes, a knowledge map, and spaced review.

Get started free