Skip to content
Saed Sayad

Numerical vs. Numerical

Analyze two numerical variables with scatter plots and the Pearson correlation coefficient: formula, interpretation, and a worked temperature-humidity example.

4 min read · Updated August 8, 2026

Two numerical variables invite the most visual of all bivariate analyses: put one on each axis, draw one point per observation, and look. The scatter plot comes first; the correlation coefficient then compresses what you see into a single number.

Scatter Plot

A scatter plot is a useful visual representation of the relationship between two numerical variables, and it is usually drawn before working out a linear correlation or fitting a regression line. The resulting pattern indicates the type (linear or non-linear) and the strength of the relationship: a tight diagonal cloud suggests strong linear association, a bent cloud a non-linear one, and a round blob no association at all.

You can add information to a two-dimensional scatter plot — for example, labeling or coloring points to show the level of a third variable. With many variables in a dataset, the standard overview is a scatter plot matrix: all possible pairwise scatter plots arranged in a grid, so every numerical relationship gets one glance.

Scatter plot of humidity versus temperature for the 14-day golf dataset: points trend slightly upward to the right, indicating a weak positive linear relationship.
Scatter plot of humidity against temperature.
Scatter plot matrix of the four Iris measurements: a grid showing every pairwise scatter plot among sepal length, sepal width, petal length, and petal width, with petal dimensions showing strong linear trends.
Scatter plot matrix: every pairwise relationship of the Iris measurements at a glance.

Linear Correlation

Linear correlation quantifies the strength of a linear relationship between two numerical variables. When there is no correlation, there is no tendency for the values of one quantity to increase or decrease with the values of the second. The Pearson correlation coefficient is the covariance of the two variables, normalized by their standard deviations:

r=i=1n(xixˉ)(yiyˉ)i=1n(xixˉ)2  i=1n(yiyˉ)2=Cov(x,y)sxsyr = \frac{ \sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y}) }{ \sqrt{ \sum_{i=1}^{n} (x_i - \bar{x})^2 } \; \sqrt{ \sum_{i=1}^{n} (y_i - \bar{y})^2 } } = \frac{\mathrm{Cov}(x, y)}{s_x \, s_y}

rr is always between −1 and 1: −1 means perfect negative linear correlation, +1 perfect positive, and 0 no linear correlation. It measures only linear strength — a perfect parabola scores near zero.

Worked Example: Temperature vs. Humidity

The legacy example uses the 14 days of the Play Golf dataset, this time with the raw numerical values of temperature and humidity:

Day1234567891011121314
Temperature8364728170686575718580726975
Humidity8665907596807080918590957070

The means are xˉ=73.57\bar{x} = 73.57 (temperature) and yˉ=81.64\bar{y} = 81.64 (humidity). Computing the moments around those means (dividing by nn):

VarianceCovarianceCorrelation
Temperature40.1019.780.32
Humidity98.23

The positive covariance says the variables move in the same direction on average; normalizing gives

r=19.7840.1098.230.32,r = \frac{19.78}{\sqrt{40.10} \cdot \sqrt{98.23}} \approx 0.32,

a weak positive linear correlation between temperature and humidity. Hotter days tended to be slightly more humid in this sample, but the relationship explains little of the variation — consistent with the loose cloud in the scatter plot.

In Practice

df.corr() produces the full correlation matrix in pandas, scipy.stats.pearsonr adds a p-value, and sns.pairplot renders the scatter plot matrix. Correlation analysis is a standard feature-screening step: drop one of two near-perfectly correlated predictors (multicollinearity hurts linear models), but remember that tree ensembles like XGBoost are insensitive to monotone transformations and can exploit non-linear structure that rr misses entirely.

Common Pitfalls

  • Equating r=0r = 0 with independence — non-linear relationships are invisible to Pearson’s rr.
  • Ignoring outliers. A single extreme point can manufacture or destroy a correlation; check the plot.
  • Confusing correlation with causation, especially in time-linked data with trends.
  • Comparing rr across different ranges — restricting the range of xx mechanically shrinks rr.
  • Reporting rr without nn. A correlation of 0.9 on 5 points means far less than 0.4 on 5,000.

Summary

Scatter plots reveal the form and strength of a two-numerical-variable relationship; the Pearson coefficient compresses the linear part into a number between −1 and 1. The temperature–humidity example shows the workflow end to end: plot, compute covariance, normalize, and interpret — here landing on a weak r0.32r \approx 0.32.