1. Learn
  2. /
  3. Courses
  4. /
  5. Inferential Statistics

Exercise

Multiple R squared II

We know that the multiple R squared for our model is 0.7196303 - this means that our model including money and smiling is about 72% better than just using the mean to predict how much someone will like us.

Let's break down how R found this value to calculate it manually ourselves.

To find this we need to look at the difference between the mean amount that our sample liked us, compared to the observed observed amount they liked us - if we square and sum this value we have the total sum of squares. We can also look at the difference between the predicted amount that our sample liked us according to our model, compared to the observed observed amount they liked us - if we square and sum this value we have the residual sum of squares.

R gives us the residuals from our model automatically. We can index it from lm() using the $. For example, lm(y ~ X1 + X2)$residual. Easy!

The total sum of squares is pretty straight forward too. We find the mean of liking using the function mean() - for example mean(y) and subtract every value of y from this. For example, mean(y) - y.

The values produced by R come out as a vector of numbers. To square these values we can use ^2, and to sum we put the vectors inside the function sum(). For example,sum((mean(y) - y)^2). If we find these values and assign them to objects we can do anything we like with them!

Instructions

100 XP
  • Obtain the residual sum of squares and assign to object ssr. Remember to use brackets to square and sum!
  • Obtain the total sum of squares and assign to object sst. Again, remember to use brackets to square and sum!
  • Use sst and ssr to calculate the multiple R squared.