Get startedGet started for free

Putting It Together: Regression

Let's try to put it all together. You've conducted a study looking at how much money people have (dependent variable) and their education level (independent variable). Let's check some different things in your data!

This exercise is part of the course

Basic Statistics

View Course

Exercise instructions

  • Calculate the Pearson r correlation coefficient between your two variables
  • Calculate your regression coefficients and assign them to a new variable called line
  • Print the regression coefficients you have assigned
  • Make a scatterplot of your variables. Label the graph "My Scatterplot" (remember you can do this with the main = argument)
  • Add the regression line to your scatterplot

Hands-on interactive exercise

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

# your data
money <- c(4, 3, 2, 2, 8, 1, 1, 2, 3, 4, 5, 6, 7, 9, 9, 8, 12)
education <- c(3, 4, 6, 9, 3, 3, 1, 2, 1, 4, 5, 7, 10, 8, 7, 6, 9)

# calculate the correlation between X and Y


# save regression coefficients as object "line"


# print the regression coefficients


# plot Y and X


# add the regression line

Edit and Run Code