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

Exercise

The Regression Equation

We know that the regression equation is \(y = a + bx\), where y is the variable you are predicting, a is the intercept (the value of the response variable when the predictor is 0) and b is the slope. We can calculate the value of b with the following equation: $$b = r \frac{sd_y} {sd_x}$$. Remember that x is the predictor variable and y is the response variable, and \(r\) is the correlation between the two.

We're going to have a go at manually calculating the value of the slope in our money and liking study!

To do this you'll need to use two functions: cor() and sd(). cor() is used to caculate a correlation coefficient, and takes the two variables you are interested in as its first arguments. For example: cor(variable1, variable2). sd() calculates the standard deviation of given data, and takes the name of your data object as its first argument. For example: sd(variable1). Let's put these to use in your script!

Instructions

100 XP
  • Add code your script to assign the correlation between liking and money to cxy.
  • Add code to your script to assign the standard deviation of money to sx.
  • Add code to your script to assign the standard deviation of liking to sy.
  • In your script, use cxy, sx and sy to calculate the slope using the slope equation.