Get startedGet started for free

Multiple R squared I

The R squared represents the proportion of improvement in the model from using the regression line over using the mean. In our case, it looks at how we can predict how much someone will like us based on how much money we give them, and how much we smile at them, compared to just using the average amount that someone likes us.

R gives us this automatically when we use summary() on the model we found using lm(). summary() tells us a lot about the model. To extract the R squared in particular, we can use the $. For example, summary(*regression model*)$r.squared would return the R squared value. Let's try this!

This exercise is part of the course

Inferential Statistics

View Course

Exercise instructions

  • In your console, use the summary() function on our lm() model, and assign the resulting object to variable mod1.
  • In your console, use the $ to print the value of the R-squared from mod1.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Vector containing the amount of money you gave participants (predictor)
money <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

# Vector containing how much you smiled (predictor)
smile <- c(0.6, 0.7, 1.0, 0.1, 0.3, 0.1, 0.4, 0.8, 0.9, 0.2)

# Vector containing the amount the participants liked you (response)
liking <- c(2.2, 2.8, 4.5, 3.1, 8.7, 5.0, 4.5, 8.8, 9.0, 9.2)

# Assign the summary of lm(liking ~ smile + money) to 'mod1'
mod1 <- summary(lm(liking ~ smile + money))

# Print the R-squared of 'mod1'
Edit and Run Code