:

## Geometric interpretation of correlation and regression

Maple

I was introduced to the geometric interpretation of correlation and linear regression recently.

Orignially due to the famous statistician R.A.Fisher, the idea is that the correlation between
two variables is the cosine of the angle between the 2 vectors in n-dimensional space.
This can be demonstrated in Maple as follows:

First, we represent each variable as a vector and transform it so that it is centred at its
mean and has a length equal to the standard deviation of the original vector.
Here is a simple procedure which does that:

trf := proc(a::Vector)
# transformation of a vector to a new vector
# centred about it's mean, with length equal
# to the original vector's standard deviation
uses LinearAlgebra, Statistics:
local i,b,m,n:
m:=Mean(a): n:=Dimension(a):
b:= Vector(n):
for i from 1 to n do
b[i]:= evalf((a[i]-m)/(sqrt(n-1))):
end do:
return b:
end proc:

Then it is extremely simple to find the correlation

with(Statistics):with(LinearAlgebra):
randomize(1):
y:=Sample(Normal(0,1),10):
x:=Sample(Normal(0,1),10):

Correlation(x,y);cos(VectorAngle(trf(x),trf(y)));

0.3639995161
0.3639995157

This can then be readily extended to ordinarly least squares regression, because
the regression coefficient is simply the magnitude of the orthogonal projection of
the response vector on the dependent vector:

`Norm(trf(y),2)*cos(VectorAngle(trf(x),trf(y)))/Norm(trf(x),2);                          0.1759074772LinearFit([1,t], x, y, t);   0.2675455672  + 0.1759074773 t`

﻿