R-squared

The R-squared can roughly be considered as a measure of how much the model is able to explain what's going on within the data. More formally, it measures how much of the variability observed within the response variable is explained from the model.

This value is actually closely related to the error measure we were seeing before, since one of its most common definitions is one minus the ratio between the total sum of squared errors and the total sum of squares (TSS):

The total sum of squares can be considered as the total variance observed within a set of values of the response variable, and is formally defined as:

As you can see, we are talking about the sum of all the differences from the mean raised to the second power. Let's take back the second model we were looking at before and compute this value:

x y y_estimated
4 8 7,80
5 10 9,75
6 12 11,70
7 14 13,65
8 16 15,60
9 18 17,55
10 20 19,50
11 22 21,45
12 24 23,40
13 26 25,35
14 28 27,30
15 30 29,25
16 32 31,20
17 34 33,15
18 36 35,10
19 38 37,05
20 40 39,00
21 42 40,95

 

First of all, we compute the mean of our population, which results in being equal to 25. We then compute for each observation the difference between the y and 25, and then raise it to the second power:

x y y-mean(y) (y-mean(y))^2
4 8 -17,00 289
5 10 -15,00 225
6 12 -13,00 169
7 14 -11,00 121
8 16 -9,00 81
9 18 -7,00 49
10 20 -5,00 25
11 22 -3,00 9
12 24 -1,00 1
13 26 1,00 1
14 28 3,00 9
15 30 5,00 25
16 32 7,00 49
17 34 9,00 81
18 36 11,00 121
19 38 13,00 169
20 40 15,00 225
21 42 17,00 289

 

Summing up the last column, we obtain the TSS, which is roughly equal to 1,938. To compute the R-squared we just have to obtain the ratio between the total sum of squared errors, also called residual sum of squares, and TSS, and compute its complement to unity. The residual sum of squares can be computed as the sum of the column of errors raised to the second we previously computed, and it results equal to 8,24.

Our R-squared will therefore be equal to 1- 8,24/1938 = 0,99; or 99%.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset