Skip to content

Correlation and Regression (Extended)

Correlation and Regression (Extended Treatment)

Section titled “Correlation and Regression (Extended Treatment)”

This document covers scatter diagrams, the product moment correlation coefficient, Spearman’s rank Correlation, least squares regression, and residual analysis.


A scatter diagram (scatter plot) displays pairs of values (xi,yi)(x_i, y_i) as points on a Coordinate grid. Visual inspection reveals:

  • The direction of association (positive, negative, or none).
  • The strength of association (strong, moderate, weak).
  • The shape of the relationship (linear, curved, clustered).
  • The presence of outliers.
PatternDescription
Strong +Points lie close to an upward-sloping line
Moderate +General upward trend with more scatter
Weak +Slight upward tendency, much scatter
No correlationNo discernible pattern
Strong -Points lie close to a downward-sloping line
Non-linearClear pattern but not a straight line

An outlier is a data point that lies far from the general pattern. Outliers can:

  • Be genuine extreme values.
  • Result from measurement errors.
  • Significantly affect the correlation coefficient and regression line.

2. Product Moment Correlation Coefficient (PMCC)

Section titled “2. Product Moment Correlation Coefficient (PMCC)”

The product moment correlation coefficient (also called Pearson’s correlation coefficient) For a sample of nn pairs (xi,yi)(x_i, y_i) is:

r=SxySxxSyyr = \frac{S_{xy}}{\sqrt{S_{xx}\,S_{yy}}}

Where:

Sxy=(xixˉ)(yiyˉ)=xiyinxˉyˉS_{xy} = \sum(x_i - \bar{x})(y_i - \bar{y}) = \sum x_i y_i - n\bar{x}\bar{y}

Sxx=(xixˉ)2=xi2nxˉ2S_{xx} = \sum(x_i - \bar{x})^2 = \sum x_i^2 - n\bar{x}^2

Syy=(yiyˉ)2=yi2nyˉ2S_{yy} = \sum(y_i - \bar{y})^2 = \sum y_i^2 - n\bar{y}^2

  • 1r1-1 \leq r \leq 1.
  • r=1r = 1: perfect positive linear correlation.
  • r=1r = -1: perfect negative linear correlation.
  • r=0r = 0: no linear correlation (but there may be a non-linear relationship).
  • rr is independent of the units of measurement.
  • rr is unchanged if both variables are transformed linearly (x=ax+bx' = ax + b, y=cy+dy' = cy + d with a,c>0a, c \gt 0).

2.3 Proof that r1|r| \leq 1

Section titled “2.3 Proof that ∣r∣≤1|r| \leq 1∣r∣≤1”

Proof. By the Cauchy-Schwarz inequality:

(aibi)2(ai2) ⁣(bi2)\left(\sum a_i b_i\right)^2 \leq \left(\sum a_i^2\right)\!\left(\sum b_i^2\right)

Setting ai=xixˉa_i = x_i - \bar{x} and bi=yiyˉb_i = y_i - \bar{y}:

Sxy2SxxSyyS_{xy}^2 \leq S_{xx}\,S_{yy}

r2=Sxy2SxxSyy1    r1r^2 = \frac{S_{xy}^2}{S_{xx}\,S_{yy}} \leq 1 \implies |r| \leq 1 \quad \blacksquare

Problem. Find the PMCC for the following data:

xx246810
yy35479

n = 5$$\bar{x} = 6$$\bar{y} = 5.6.

xiyi=6+20+24+56+90=196\sum x_i y_i = 6 + 20 + 24 + 56 + 90 = 196

Sxy=1965(6)(5.6)=196168=28S_{xy} = 196 - 5(6)(5.6) = 196 - 168 = 28

\sum x_i^2 = 4 + 16 + 36 + 64 + 100 = 220$$S_{xx} = 220 - 5(36) = 40

\sum y_i^2 = 9 + 25 + 16 + 49 + 81 = 180$$S_{yy} = 180 - 5(31.36) = 180 - 156.8 = 23.2

r=2840×23.2=28928=2830.460.919r = \frac{28}{\sqrt{40 \times 23.2}} = \frac{28}{\sqrt{928}} = \frac{28}{30.46} \approx 0.919

This indicates strong positive linear correlation.

When data values are large, coding simplifies calculations. Use u=xacu = \dfrac{x - a}{c} and v=ybdv = \dfrac{y - b}{d} where a,ba, b are shift values and c,dc, d are scaling values.

The PMCC is unchanged by coding: rxy=ruvr_{xy} = r_{uv}.


3. Spearman’s Rank Correlation Coefficient

Section titled “3. Spearman’s Rank Correlation Coefficient”

Spearman’s rank correlation coefficient rsr_s measures the strength of the monotonic Relationship between two variables:

rs=16di2n(n21)r_s = 1 - \frac{6\sum d_i^2}{n(n^2 - 1)}

Where di=rank(xi)rank(yi)d_i = \mathrm{rank}(x_i) - \mathrm{rank}(y_i) is the difference in ranks for the ii-th pair.

  • Data is ordinal (ranked categories).
  • The relationship is monotonic but not necessarily linear.
  • There are significant outliers that would distort the PMCC.
  • The data contains tied ranks.

When values are tied, assign the average rank to all tied values. For example, if two values Are tied for ranks 3 and 4, both receive rank 3.5.

When ties exist, the simplified formula is only approximate. A more accurate formula uses:

rs=SxySxxSyyr_s = \frac{S_{xy}}{\sqrt{S_{xx}\,S_{yy}}}

Applied to the rank data.

Problem. Two judges rank 6 competitors:

CompetitorABCDEF
Judge 1132546
Judge 2213654
did_i-12-1-1-12

di2=1+4+1+1+1+4=12\sum d_i^2 = 1 + 4 + 1 + 1 + 1 + 4 = 12

rs=16×126(35)=172210=10.343=0.657r_s = 1 - \frac{6 \times 12}{6(35)} = 1 - \frac{72}{210} = 1 - 0.343 = 0.657

This indicates moderate positive agreement between the judges.

Problem. Find rsr_s for the following data:

xx1020203040
yy58121520

Ranks of xx: 1, 2.5, 2.5, 4, 5 (tied at 20).

Ranks of yy: 1, 2, 3, 4, 5.

did_i: 0, 0.5, -0.5, 0, 0.

di2=0+0.25+0.25+0+0=0.5\sum d_i^2 = 0 + 0.25 + 0.25 + 0 + 0 = 0.5

rs=16×0.55×24=13120=10.025=0.975r_s = 1 - \frac{6 \times 0.5}{5 \times 24} = 1 - \frac{3}{120} = 1 - 0.025 = 0.975

Very strong positive monotonic relationship.


The least squares regression line of yy on xx is the line y=a+bxy = a + bx that minimises the Sum of squared residuals:

S=i=1n(yiabxi)2S = \sum_{i=1}^{n}(y_i - a - bx_i)^2

Setting Sa=0\dfrac{\partial S}{\partial a} = 0 and Sb=0\dfrac{\partial S}{\partial b} = 0:

b=SxySxx=(xixˉ)(yiyˉ)(xixˉ)2b = \frac{S_{xy}}{S_{xx}} = \frac{\sum(x_i - \bar{x})(y_i - \bar{y})}{\sum(x_i - \bar{x})^2}

a=yˉbxˉa = \bar{y} - b\bar{x}

Key property: The regression line always passes through the point (xˉ,yˉ)(\bar{x}, \bar{y}).

Sa=2(yiabxi)=0    na+bxi=yi\frac{\partial S}{\partial a} = -2\sum(y_i - a - bx_i) = 0 \implies na + b\sum x_i = \sum y_i

Sb=2xi(yiabxi)=0    axi+bxi2=xiyi\frac{\partial S}{\partial b} = -2\sum x_i(y_i - a - bx_i) = 0 \implies a\sum x_i + b\sum x_i^2 = \sum x_i y_i

These are the normal equations. Dividing the first by nn gives yˉ=a+bxˉ\bar{y} = a + b\bar{x} Confirming the line passes through the mean point.

Using the data from Section 2.4:

b=SxySxx=2840=0.7b = \dfrac{S_{xy}}{S_{xx}} = \dfrac{28}{40} = 0.7

a=yˉbxˉ=5.60.7(6)=5.64.2=1.4a = \bar{y} - b\bar{x} = 5.6 - 0.7(6) = 5.6 - 4.2 = 1.4

y=1.4+0.7xy = 1.4 + 0.7x

To predict yy when x=7x = 7: y=1.4+4.9=6.3y = 1.4 + 4.9 = 6.3.

The regression line of xx on yy (used when predicting xx from yy) is:

x=xˉ+SxySyy(yyˉ)x = \bar{x} + \frac{S_{xy}}{S_{yy}}(y - \bar{y})

Important: The two regression lines are different unless r=1|r| = 1. The line of yy on xx Minimises vertical residuals; the line of xx on yy minimises horizontal residuals.

  1. Interpolation (predicting within the data range) is generally reliable.
  2. Extrapolation (predicting outside the data range) is unreliable — the relationship may not hold.
  3. The regression line assumes a linear relationship.
  4. The model assumes the residuals are independent and normally distributed with constant variance (homoscedasticity).

Mathematics provides the language for describing patterns, relationships, and change. Functions transform inputs to outputs like machines, calculus measures how things change and accumulate, and probability quantifies uncertainty. The power of mathematics lies in its ability to model real-world situations abstractly, allowing us to solve problems and make predictions across science, engineering, and everyday life.