Supplement 2.1: Point Clouds and Linear Regression Lines (3/3)

The correlation coefficient

We consider a number of data points P( x i , y i ) , with i=1, ..., n. The points are defined by a set of n couples of features x i and y i . As already shown, one can calculate the centroid of the point cloud and the best-fit straight line. We are interested in a quantity which gives evidence of the deviation of the points from the best-fit line. As an example we focus on point P( x 5 , y 5 ) in the graph below, and on its position P( x 5 ,f( x 5 ) ) as predicted by the best-fit line.

Zoom Sign
water temperatures in October
Water temperatures in October near Spiekeroog island (blue dots), best-fit line (red broken line) and centroid P( x ¯ , y ¯ ) . Point P( x 5 , y 5 ) is compared with its position predicted by the best-fit line P( x 5 ,f( x 5 ) ) .

The position of P( x 5 , y 5 ) is now explained in two steps, as illustrated in the graph below:

  • the location of point P( x 5 ,f( x 5 ) ) with the same x=x5, predicted by the best-fit line:   f( x 5 ) y ¯
    (deviation predicted by the best-fit line)
  • the deviation of P( x 5 , y 5 ) with respect to P( x 5 ,f( x 5 ) ) : y 5 f( x 5 )
    (unexplained deviation)
Zoom Sign
Abweichungen von Punkt 5
Explanation of the position of P( x 5 , y 5 ) in two steps: part predicted through the best-fit line (lower bracket), and unexplained part (upper bracket).

This concept can be applied with all points of the point cloud, in order to represent their deviations from the best-fit line.

The quantity which gives evidence of the quality in which way the best-fit line represents the point cloud is the correlation coefficient r, defined as follows:
r= square root of the predicted squared deviations square root of the total squared deviations

r= 1 n i=1 n ( f( x i ) y ¯ ) 2 1 n i=1 n ( y i y ¯ ) 2 = i=1 n ( f( x i ) y ¯ ) 2 i=1 n ( y i y ¯ ) 2

The linear correlation coefficient

The equation of the correlation coefficient given in chapter 2 on page Linear Regression Analysis (3/3) differs from the equation given in the left column. It holds for best-fit straight lines only (hence: linear correlation coefficient), while the equation given in the left column is also valid for curved best-fit lines.

The equation for the linear correlation coefficient can be obtained by squaring the equation given in the left column, and by repacing f( x i ) y ¯ with a( x i x ¯ ) :

r 2 = a 2 i=1 n ( x i x ¯ ) 2 i=1 n ( y i y ¯ ) 2

Using the slope a given on the preceeding page yields:

r 2 = ( i=1 n ( x i x ¯ )( y i y ¯ ) ) 2 ( i=1 n ( x i x ¯ ) 2 ) 2 i=1 n ( x i x ¯ ) 2 i=1 n ( y i y ¯ ) 2

This can be simplified by cancelling:

r 2 = ( i=1 n ( x i x ¯ )( y i y ¯ ) ) 2 i=1 n ( x i x ¯ ) 2 i=1 n ( y i y ¯ ) 2

It follows by taking the square root:

r= | i=1 n ( x i x ¯ )( y i y ¯ ) | i=1 n ( x i x ¯ ) 2 i=1 n ( y i y ¯ ) 2

Omitting the absolute value bars,

r= i=1 n ( x i x ¯ )( y i y ¯ ) i=1 n ( x i x ¯ ) 2 i=1 n ( y i y ¯ ) 2

allows the correlation coefficient to take on negative values: usually r has the same sign as a.

It is advantageous with this equation that it includes the coordinates of the centroid and the data points only. The equation given in the left column requires also the coordinate valus of the best fit line.