This document covers scatter diagrams, the product moment correlation coefficient, Spearman’s rank Correlation, least squares regression, and residual analysis.
it Does not capture non-linear relationships. Always plot your data before interpreting correlation Values. A scatter diagram (scatter plot) displays pairs of values ( x i , y i ) (x_i, y_i) ( 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 . Pattern Description Strong + Points lie close to an upward-sloping line Moderate + General upward trend with more scatter Weak + Slight upward tendency, much scatter No correlation No discernible pattern Strong - Points lie close to a downward-sloping line Non-linear Clear 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. coefficient. Always examine Your scatter diagram before relying on numerical measures. The product moment correlation coefficient (also called Pearson’s correlation coefficient) For a sample of n n n pairs ( x i , y i ) (x_i, y_i) ( x i , y i ) is:
r = S x y S x x S y y r = \frac{S_{xy}}{\sqrt{S_{xx}\,S_{yy}}} r = S xx S y y S x y
Where:
S x y = ∑ ( x i − x ˉ ) ( y i − y ˉ ) = ∑ x i y i − n x ˉ y ˉ S_{xy} = \sum(x_i - \bar{x})(y_i - \bar{y}) = \sum x_i y_i - n\bar{x}\bar{y} S x y = ∑ ( x i − x ˉ ) ( y i − y ˉ ) = ∑ x i y i − n x ˉ y ˉ
S x x = ∑ ( x i − x ˉ ) 2 = ∑ x i 2 − n x ˉ 2 S_{xx} = \sum(x_i - \bar{x})^2 = \sum x_i^2 - n\bar{x}^2 S xx = ∑ ( x i − x ˉ ) 2 = ∑ x i 2 − n x ˉ 2
S y y = ∑ ( y i − y ˉ ) 2 = ∑ y i 2 − n y ˉ 2 S_{yy} = \sum(y_i - \bar{y})^2 = \sum y_i^2 - n\bar{y}^2 S y y = ∑ ( y i − y ˉ ) 2 = ∑ y i 2 − n y ˉ 2
− 1 ≤ r ≤ 1 -1 \leq r \leq 1 − 1 ≤ r ≤ 1 .r = 1 r = 1 r = 1 : perfect positive linear correlation.r = − 1 r = -1 r = − 1 : perfect negative linear correlation.r = 0 r = 0 r = 0 : no linear correlation (but there may be a non-linear relationship).r r r is independent of the units of measurement.r r r is unchanged if both variables are transformed linearly (x ′ = a x + b x' = ax + b x ′ = a x + b , y ′ = c y + d y' = cy + d y ′ = cy + d with a , c > 0 a, c \gt 0 a , c > 0 ).Proof. By the Cauchy-Schwarz inequality:
( ∑ a i b i ) 2 ≤ ( ∑ a i 2 ) ( ∑ b i 2 ) \left(\sum a_i b_i\right)^2 \leq \left(\sum a_i^2\right)\!\left(\sum b_i^2\right) ( ∑ a i b i ) 2 ≤ ( ∑ a i 2 ) ( ∑ b i 2 )
Setting a i = x i − x ˉ a_i = x_i - \bar{x} a i = x i − x ˉ and b i = y i − y ˉ b_i = y_i - \bar{y} b i = y i − y ˉ :
S x y 2 ≤ S x x S y y S_{xy}^2 \leq S_{xx}\,S_{yy} S x y 2 ≤ S xx S y y
r 2 = S x y 2 S x x S y y ≤ 1 ⟹ ∣ r ∣ ≤ 1 ■ r^2 = \frac{S_{xy}^2}{S_{xx}\,S_{yy}} \leq 1 \implies |r| \leq 1 \quad \blacksquare r 2 = S xx S y y S x y 2 ≤ 1 ⟹ ∣ r ∣ ≤ 1 ■
Problem. Find the PMCC for the following data:
n = 5$$\bar{x} = 6$$\bar{y} = 5.6 .
∑ x i y i = 6 + 20 + 24 + 56 + 90 = 196 \sum x_i y_i = 6 + 20 + 24 + 56 + 90 = 196 ∑ x i y i = 6 + 20 + 24 + 56 + 90 = 196
S x y = 196 − 5 ( 6 ) ( 5.6 ) = 196 − 168 = 28 S_{xy} = 196 - 5(6)(5.6) = 196 - 168 = 28 S x y = 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 = 28 40 × 23.2 = 28 928 = 28 30.46 ≈ 0.919 r = \frac{28}{\sqrt{40 \times 23.2}} = \frac{28}{\sqrt{928}} = \frac{28}{30.46} \approx 0.919 r = 40 × 23.2 28 = 928 28 = 30.46 28 ≈ 0.919
This indicates strong positive linear correlation.
When data values are large, coding simplifies calculations. Use u = x − a c u = \dfrac{x - a}{c} u = c x − a and v = y − b d v = \dfrac{y - b}{d} v = d y − b where a , b a, b a , b are shift values and c , d c, d c , d are scaling values.
The PMCC is unchanged by coding: r x y = r u v r_{xy} = r_{uv} r x y = r uv .
Spearman’s rank correlation coefficient r s r_s r s measures the strength of the monotonic Relationship between two variables:
r s = 1 − 6 ∑ d i 2 n ( n 2 − 1 ) r_s = 1 - \frac{6\sum d_i^2}{n(n^2 - 1)} r s = 1 − n ( n 2 − 1 ) 6 ∑ d i 2
Where d i = r a n k ( x i ) − r a n k ( y i ) d_i = \mathrm{rank}(x_i) - \mathrm{rank}(y_i) d i = rank ( x i ) − rank ( y i ) is the difference in ranks for the i i i -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:
r s = S x y S x x S y y r_s = \frac{S_{xy}}{\sqrt{S_{xx}\,S_{yy}}} r s = S xx S y y S x y
Applied to the rank data.
Problem. Two judges rank 6 competitors:
Competitor A B C D E F Judge 1 1 3 2 5 4 6 Judge 2 2 1 3 6 5 4
∑ d i 2 = 1 + 4 + 1 + 1 + 1 + 4 = 12 \sum d_i^2 = 1 + 4 + 1 + 1 + 1 + 4 = 12 ∑ d i 2 = 1 + 4 + 1 + 1 + 1 + 4 = 12
r s = 1 − 6 × 12 6 ( 35 ) = 1 − 72 210 = 1 − 0.343 = 0.657 r_s = 1 - \frac{6 \times 12}{6(35)} = 1 - \frac{72}{210} = 1 - 0.343 = 0.657 r s = 1 − 6 ( 35 ) 6 × 12 = 1 − 210 72 = 1 − 0.343 = 0.657
This indicates moderate positive agreement between the judges.
Problem. Find r s r_s r s for the following data:
Ranks of x x x : 1, 2.5, 2.5, 4, 5 (tied at 20).
Ranks of y y y : 1, 2, 3, 4, 5.
d i d_i d i : 0, 0.5, -0.5, 0, 0.
∑ d i 2 = 0 + 0.25 + 0.25 + 0 + 0 = 0.5 \sum d_i^2 = 0 + 0.25 + 0.25 + 0 + 0 = 0.5 ∑ d i 2 = 0 + 0.25 + 0.25 + 0 + 0 = 0.5
r s = 1 − 6 × 0.5 5 × 24 = 1 − 3 120 = 1 − 0.025 = 0.975 r_s = 1 - \frac{6 \times 0.5}{5 \times 24} = 1 - \frac{3}{120} = 1 - 0.025 = 0.975 r s = 1 − 5 × 24 6 × 0.5 = 1 − 120 3 = 1 − 0.025 = 0.975
Very strong positive monotonic relationship.
The least squares regression line of y y y on x x x is the line y = a + b x y = a + bx y = a + b x that minimises the Sum of squared residuals:
S = ∑ i = 1 n ( y i − a − b x i ) 2 S = \sum_{i=1}^{n}(y_i - a - bx_i)^2 S = ∑ i = 1 n ( y i − a − b x i ) 2
Setting ∂ S ∂ a = 0 \dfrac{\partial S}{\partial a} = 0 ∂ a ∂ S = 0 and ∂ S ∂ b = 0 \dfrac{\partial S}{\partial b} = 0 ∂ b ∂ S = 0 :
b = S x y S x x = ∑ ( x i − x ˉ ) ( y i − y ˉ ) ∑ ( x i − x ˉ ) 2 b = \frac{S_{xy}}{S_{xx}} = \frac{\sum(x_i - \bar{x})(y_i - \bar{y})}{\sum(x_i - \bar{x})^2} b = S xx S x y = ∑ ( x i − x ˉ ) 2 ∑ ( x i − x ˉ ) ( y i − y ˉ )
a = y ˉ − b x ˉ a = \bar{y} - b\bar{x} a = y ˉ − b x ˉ
Key property: The regression line always passes through the point ( x ˉ , y ˉ ) (\bar{x}, \bar{y}) ( x ˉ , y ˉ ) .
∂ S ∂ a = − 2 ∑ ( y i − a − b x i ) = 0 ⟹ n a + b ∑ x i = ∑ y i \frac{\partial S}{\partial a} = -2\sum(y_i - a - bx_i) = 0 \implies na + b\sum x_i = \sum y_i ∂ a ∂ S = − 2 ∑ ( y i − a − b x i ) = 0 ⟹ na + b ∑ x i = ∑ y i
∂ S ∂ b = − 2 ∑ x i ( y i − a − b x i ) = 0 ⟹ a ∑ x i + b ∑ x i 2 = ∑ x i y i \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 ∂ b ∂ S = − 2 ∑ x i ( y i − a − b x i ) = 0 ⟹ a ∑ x i + b ∑ x i 2 = ∑ x i y i
These are the normal equations . Dividing the first by n n n gives y ˉ = a + b x ˉ \bar{y} = a + b\bar{x} y ˉ = a + b x ˉ Confirming the line passes through the mean point.
Using the data from Section 2.4:
b = S x y S x x = 28 40 = 0.7 b = \dfrac{S_{xy}}{S_{xx}} = \dfrac{28}{40} = 0.7 b = S xx S x y = 40 28 = 0.7
a = y ˉ − b x ˉ = 5.6 − 0.7 ( 6 ) = 5.6 − 4.2 = 1.4 a = \bar{y} - b\bar{x} = 5.6 - 0.7(6) = 5.6 - 4.2 = 1.4 a = y ˉ − b x ˉ = 5.6 − 0.7 ( 6 ) = 5.6 − 4.2 = 1.4
y = 1.4 + 0.7 x y = 1.4 + 0.7x y = 1.4 + 0.7 x
To predict y y y when x = 7 x = 7 x = 7 : y = 1.4 + 4.9 = 6.3 y = 1.4 + 4.9 = 6.3 y = 1.4 + 4.9 = 6.3 .
The regression line of x x x on y y y (used when predicting x x x from y y y ) is:
x = x ˉ + S x y S y y ( y − y ˉ ) x = \bar{x} + \frac{S_{xy}}{S_{yy}}(y - \bar{y}) x = x ˉ + S y y S x y ( y − y ˉ )
Important: The two regression lines are different unless ∣ r ∣ = 1 |r| = 1 ∣ r ∣ = 1 . The line of y y y on x x x Minimises vertical residuals; the line of x x x on y y y minimises horizontal residuals.
Interpolation (predicting within the data range) is generally reliable.Extrapolation (predicting outside the data range) is unreliable — the relationship may not hold.The regression line assumes a linear relationship. The model assumes the residuals are independent and normally distributed with constant variance (homoscedasticity). vice versa. Use the appropriate regression line for the direction of prediction.A residual for the i i i -th data point is the difference between the observed value and the Predicted value:
e i = y i − y ^ i = y i − ( a + b x i ) e_i = y_i - \hat{y}_i = y_i - (a + bx_i) e i = y i − y ^ i = y i − ( a + b x i )
∑ e i = 0 \sum e_i = 0 ∑ e i = 0 (the residuals sum to zero).∑ x i e i = 0 \sum x_i e_i = 0 ∑ x i e i = 0 (residuals are uncorrelated with x x x ).The mean of the residuals is zero. Plotting residuals against x x x (or against y ^ \hat{y} y ^ ) reveals:
Random scatter around zero: the linear model is appropriate.Curved pattern: a non-linear model would be better.Funnel shape: the variance is not constant (heteroscedasticity).Large outliers: individual points with unusually large residuals.Using the data and regression line y = 1.4 + 0.7 x y = 1.4 + 0.7x y = 1.4 + 0.7 x from Section 4.3:
x x x y y y y ^ \hat{y} y ^ Residual e e e 2 3 2.8 0.2 4 5 4.2 0.8 6 4 5.6 -1.6 8 7 7.0 0.0 10 9 8.4 0.6
Check: ∑ e = 0.2 + 0.8 − 1.6 + 0 + 0.6 = 0 \sum e = 0.2 + 0.8 - 1.6 + 0 + 0.6 = 0 ∑ e = 0.2 + 0.8 − 1.6 + 0 + 0.6 = 0 .
The residual at x = 6 x = 6 x = 6 is relatively large (− 1.6 -1.6 − 1.6 ), suggesting this point deviates most from The linear model.
Find the PMCC for the data: (1, 2), (2, 3), (3, 5), (4, 4), (5, 7), (6, 8).
Solution n = 6$$\bar{x} = 3.5$$\bar{y} = 4.833 .
S x x = 1 + 0.25 + 0.25 + 0.25 + 2.25 + 6.25 = 17.5 S_{xx} = 1 + 0.25 + 0.25 + 0.25 + 2.25 + 6.25 = 17.5 S xx = 1 + 0.25 + 0.25 + 0.25 + 2.25 + 6.25 = 17.5 .
S y y = 7.36 + 3.36 + 0.028 + 0.694 + 4.694 + 10.03 = 26.17 S_{yy} = 7.36 + 3.36 + 0.028 + 0.694 + 4.694 + 10.03 = 26.17 S y y = 7.36 + 3.36 + 0.028 + 0.694 + 4.694 + 10.03 = 26.17 .
S x y = ( 1 − 3.5 ) ( 2 − 4.833 ) + … = ( − 2.5 ) ( − 2.833 ) + ( − 1.5 ) ( − 1.833 ) + ( − 0.5 ) ( 0.167 ) + ( 0.5 ) ( − 0.833 ) + ( 1.5 ) ( 2.167 ) + ( 2.5 ) ( 3.167 ) S_{xy} = (1 - 3.5)(2 - 4.833) + \ldots = (-2.5)(-2.833) + (-1.5)(-1.833) + (-0.5)(0.167) + (0.5)(-0.833) + (1.5)(2.167) + (2.5)(3.167) S x y = ( 1 − 3.5 ) ( 2 − 4.833 ) + … = ( − 2.5 ) ( − 2.833 ) + ( − 1.5 ) ( − 1.833 ) + ( − 0.5 ) ( 0.167 ) + ( 0.5 ) ( − 0.833 ) + ( 1.5 ) ( 2.167 ) + ( 2.5 ) ( 3.167 )
= 7.083 + 2.750 − 0.083 − 0.417 + 3.250 + 7.917 = 20.5 = 7.083 + 2.750 - 0.083 - 0.417 + 3.250 + 7.917 = 20.5 = 7.083 + 2.750 − 0.083 − 0.417 + 3.250 + 7.917 = 20.5
r = 20.5 17.5 × 26.17 = 20.5 457.98 = 20.5 21.40 ≈ 0.958 r = \dfrac{20.5}{\sqrt{17.5 \times 26.17}} = \dfrac{20.5}{\sqrt{457.98}} = \dfrac{20.5}{21.40} \approx 0.958 r = 17.5 × 26.17 20.5 = 457.98 20.5 = 21.40 20.5 ≈ 0.958
Find the equation of the regression line of y y y on x x x for the data in Problem 1, and predict y y y When x = 7 x = 7 x = 7 .
Solution b = \dfrac{20.5}{17.5} = 1.171$$a = 4.833 - 1.171(3.5) = 4.833 - 4.100 = 0.734 .
y = 0.734 + 1.171 x y = 0.734 + 1.171x y = 0.734 + 1.171 x .
When x = 7 x = 7 x = 7 : y = 0.734 + 8.200 = 8.934 ≈ 8.9 y = 0.734 + 8.200 = 8.934 \approx 8.9 y = 0.734 + 8.200 = 8.934 ≈ 8.9 .
Two teachers rank 8 students by exam performance. Calculate Spearman’s rank correlation coefficient.
Student A B C D E F G H Teacher 1 1 2 3 4 5 6 7 8 Teacher 2 3 1 4 2 6 5 8 7
Solution d i d_i d i : -2, 1, -1, 2, -1, 1, -1, 1.
∑ d i 2 = 4 + 1 + 1 + 4 + 1 + 1 + 1 + 1 = 14 \sum d_i^2 = 4 + 1 + 1 + 4 + 1 + 1 + 1 + 1 = 14 ∑ d i 2 = 4 + 1 + 1 + 4 + 1 + 1 + 1 + 1 = 14 .
r s = 1 − 6 × 14 8 × 63 = 1 − 84 504 = 1 − 0.1667 = 0.833 r_s = 1 - \dfrac{6 \times 14}{8 \times 63} = 1 - \dfrac{84}{504} = 1 - 0.1667 = 0.833 r s = 1 − 8 × 63 6 × 14 = 1 − 504 84 = 1 − 0.1667 = 0.833 .
Losing marks by not showing sufficient working. Always write out each step, especially in proof questions.
Forgetting to check that solutions satisfy the original equation (especially with squaring both sides or dividing by variables).
Misreading the question, particularly with ‘hence’ vs ‘hence or otherwise’. The former requires using previous work.
Incorrectly applying integration by parts by choosing u u u and d v d x \frac{dv}{dx} d x d v the wrong way around.
Problem. Given the data:
Calculate the PMCC and the equation of the regression line of y y y on x x x .
Solution. n = 5 n = 5 n = 5 , x ˉ = 3 \bar{x} = 3 x ˉ = 3 , y ˉ = 6.6 \bar{y} = 6.6 y ˉ = 6.6 .
∑ x i y i = 3 + 10 + 18 + 32 + 55 = 118 \sum x_i y_i = 3 + 10 + 18 + 32 + 55 = 118 ∑ x i y i = 3 + 10 + 18 + 32 + 55 = 118 . S x y = 118 − 5 ( 3 ) ( 6.6 ) = 118 − 99 = 19 S_{xy} = 118 - 5(3)(6.6) = 118 - 99 = 19 S x y = 118 − 5 ( 3 ) ( 6.6 ) = 118 − 99 = 19 .
∑ x i 2 = 1 + 4 + 9 + 16 + 25 = 55 \sum x_i^2 = 1 + 4 + 9 + 16 + 25 = 55 ∑ x i 2 = 1 + 4 + 9 + 16 + 25 = 55 . S x x = 55 − 5 ( 9 ) = 10 S_{xx} = 55 - 5(9) = 10 S xx = 55 − 5 ( 9 ) = 10 .
∑ y i 2 = 9 + 25 + 36 + 64 + 121 = 255 \sum y_i^2 = 9 + 25 + 36 + 64 + 121 = 255 ∑ y i 2 = 9 + 25 + 36 + 64 + 121 = 255 . S y y = 255 − 5 ( 43.56 ) = 255 − 217.8 = 37.2 S_{yy} = 255 - 5(43.56) = 255 - 217.8 = 37.2 S y y = 255 − 5 ( 43.56 ) = 255 − 217.8 = 37.2 .
r = 19 10 × 37.2 = 19 19.29 ≈ 0.985 r = \frac{19}{\sqrt{10 \times 37.2}} = \frac{19}{19.29} \approx 0.985 r = 10 × 37.2 19 = 19.29 19 ≈ 0.985
Regression: b = 19 10 = 1.9 b = \frac{19}{10} = 1.9 b = 10 19 = 1.9 , a = 6.6 − 1.9 ( 3 ) = 0.9 a = 6.6 - 1.9(3) = 0.9 a = 6.6 − 1.9 ( 3 ) = 0.9 .
y = 0.9 + 1.9 x y = 0.9 + 1.9x y = 0.9 + 1.9 x
■ \blacksquare ■
Problem. Two judges score 5 contestants:
Contestant A B C D E Judge 1 7 9 5 9 3 Judge 2 6 8 7 10 4
Calculate Spearman’s rank correlation coefficient.
Solution. Judge 1 ranks: B and D tied at 3 + 4 2 = 3.5 \frac{3+4}{2} = 3.5 2 3 + 4 = 3.5 , so A=2, B=3.5, C=1, D=3.5, E=0 (not possible). Actually: scores sorted: 3(E), 5(C), 7(A), 9(B), 9(D).
Ranks: E=1, C=2, A=3, B=4.5, D=4.5.
Judge 2 ranks: E=1, A=2, C=3, B=4, D=5.
∑ d i 2 = 1 + 0.25 + 1 + 0.25 + 0 = 2.5 \sum d_i^2 = 1 + 0.25 + 1 + 0.25 + 0 = 2.5 ∑ d i 2 = 1 + 0.25 + 1 + 0.25 + 0 = 2.5 .
r s = 1 − 6 × 2.5 5 × 24 = 1 − 15 120 = 1 − 0.125 = 0.875 r_s = 1 - \frac{6 \times 2.5}{5 \times 24} = 1 - \frac{15}{120} = 1 - 0.125 = 0.875 r s = 1 − 5 × 24 6 × 2.5 = 1 − 120 15 = 1 − 0.125 = 0.875
■ \blacksquare ■
PMCC: r = S x y S x x S y y r = \frac{S_{xy}}{\sqrt{S_{xx} S_{yy}}} r = S xx S y y S x y measures linear correlation; − 1 ≤ r ≤ 1 -1 \leq r \leq 1 − 1 ≤ r ≤ 1 . Regression line of y y y on x x x : y = a + b x y = a + bx y = a + b x where b = S x y S x x b = \frac{S_{xy}}{S_{xx}} b = S xx S x y , a = y ˉ − b x ˉ a = \bar{y} - b\bar{x} a = y ˉ − b x ˉ . Spearman’s rank: r s = 1 − 6 ∑ d i 2 n ( n 2 − 1 ) r_s = 1 - \frac{6\sum d_i^2}{n(n^2-1)} r s = 1 − n ( n 2 − 1 ) 6 ∑ d i 2 measures monotonic correlation. Residuals: e i = y i − y ^ i e_i = y_i - \hat{y}_i e i = y i − y ^ i ; random scatter confirms linearity, curved pattern suggests non-linearity. Correlation does not imply causation; always inspect scatter diagrams before interpreting r r r . 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.