1 of 21

Lecture 30

Linear Regression

DATA 8

Fall 2023

2 of 21

Announcements

  • Homework 9 is due today at 11pm
  • Project 2 checkpoint due Friday 11/3
  • Full project due Friday 11/10
    • Veterans Day! No OH and staff will not be expected to answer Ed
    • Try to submit by 11/9 and get the 5 extra credit points :D
  • Tuesday 5-7 Online OH signups on Ed

3 of 21

Correlation Coefficient

4 of 21

The Correlation Coefficient r

  • Measures linear association
  • Based on standard units
  • -1 ≤ r ≤ 1
    • r = 1: scatter is perfect straight line sloping up
    • r = -1: scatter is perfect straight line sloping down
  • r = 0: No linear association; uncorrelated

r = 0

r = 0.2

r = 0.5

r = 0.8

r = 0.99

r = -0.5

5 of 21

Definition of r

average of

product of

x in standard units

and

y in standard units

Correlation Coefficient (r) =

Measures how clustered the scatter is around a straight line

6 of 21

Care in Interpretation

7 of 21

Discussion question

True or False?

If the correlation of x and y is close to 0, then knowing one cannot help us predict the other.

8 of 21

Prediction

9 of 21

Predicting Heights

  • Oval shaped

  • Moderate positive correlation

  • How can we predict child height from the parents’ average height?

Average of parents’ heights

Child’s (adult) height

10 of 21

Approach to Prediction

Average of parents’ heights

Child’s (adult) height

11 of 21

Predicted Heights

Average of parents’ heights

Child’s (adult) height

12 of 21

Nearest Neighbor Regression

A method for prediction:

  • Group each x with similar (nearby) x values
  • Average the corresponding y values for each group

For each x value, the prediction is the average of the y values in its nearby group.

The graph of these predictions is the “graph of averages”.

If the association between x and y is linear, then points in the graph of averages tend to fall on a line.

13 of 21

Where is the prediction line?

r = 0.99

14 of 21

Where is the prediction line?

r = 0.0

(Demo)

15 of 21

Linear Regression

16 of 21

Linear Regression

A statement about x and y pairs

  • Measured in standard units (su)
  • Describing the deviation of x from 0 (the average of x's)
  • And the deviation of the corresponding y from 0 (the average of y's)

On average, y deviates from 0 less than x deviates from 0

Not true for all points — a statement about averages

Regression line

correlation

17 of 21

Regression Line Equation

In original units, the regression line has this equation:

Lines can be expressed by slope & intercept

estimated y in standard units

x in standard units

18 of 21

Regression Line

Standard Units

(0, 0)

1

r

Original Units

(Average x,� Average y)

SD x

r * SD y

19 of 21

Regression Estimate

Goal: Predict y using x

To find the regression estimate of y:

  • Convert the given x to standard units
  • Multiply by r
  • That’s the regression estimate of y, but:
    • It’s in standard units
    • So convert it back to the original units of y

20 of 21

Slope and Intercept (in original units)

estimate of y = slope * x + intercept

(Demo)

21 of 21

Discussion Question

A course has a midterm (average 70; standard deviation 10)�and a really hard final (average 50; standard deviation 12)

If the scatter diagram comparing midterm & final scores for students has an oval shape with correlation 0.75, then...

What do you expect the average final score would be for students who scored 90 on the midterm?

How about 60 on the midterm?