Math 141: Lecture 18: Correlation and Regression
Math 141: Lecture 18: Correlation and Regression
Math 141: Lecture 18: Correlation and Regression
Albyn Jones1
1 Library
304
[email protected]
www.people.reed.edu/∼jones/courses/141
Correlation 0
3
● ●
●
● ●
●
● ●
● ●
●
● ● ●
● ● ●
2
● ● ●
● ● ●
● ● ●
● ● ●●●
● ●
● ● ●
● ● ● ●
● ● ● ● ● ● ●
● ●● ● ● ●
● ● ●●
● ●● ●● ●●●● ●
●● ● ● ●● ●
● ●
● ● ● ●
● ● ● ●● ●
● ● ● ● ●
● ● ● ● ●
● ●● ● ● ● ● ●● ● ● ● ●● ●● ●
●
● ● ● ● ●●● ● ●● ●●
● ●
● ● ● ● ● ●
● ● ● ● ●●●●● ●● ●● ● ●
● ● ● ●● ● ● ●● ●● ● ●
1
● ●● ●
● ● ● ●● ●
● ● ● ●● ● ●
● ● ● ●● ● ● ● ●● ● ●●
●●● ● ● ●● ●● ●● ●● ●● ●
● ● ● ● ●●● ● ● ● ● ●● ● ●● ● ●
● ●● ● ● ● ● ●● ● ● ● ●● ● ● ●
● ●
● ● ● ● ● ●●● ● ● ● ●● ●
● ● ● ●● ●●● ● ●
● ●● ● ●● ●
● ●
●●
● ● ● ● ●●● ● ● ● ●
● ●●● ● ●
● ●
● ● ● ● ● ● ●
● ● ● ● ●
● ● ● ● ● ●● ●
● ●●●● ●
●
●● ●
●● ●
●●● ● ● ●● ● ● ●
●●●● ● ● ● ●● ● ● ●● ● ● ● ●
● ● ●●●● ●● ● ● ●●● ●
● ●●● ●●● ● ● ● ● ●
● ●● ● ●● ●●● ● ● ●● ● ● ● ● ●
●
●●● ●● ●● ●● ●●● ●● ● ● ●● ● ●●●●
● ● ●
● ●● ●
● ●● ●
● ● ● ● ●● ●
● ● ●
● ● ●
● ● ● ● ● ●● ●● ●●
● ●● ● ● ●● ● ●●● ● ● ● ● ● ●
● ● ● ● ●●● ●●● ● ●●●
● ● ● ● ●● ●
0
● ●●●
y
● ●
● ●●● ●
●
●
●● ● ● ● ●
● ● ●● ● ● ●
● ●●
● ● ● ●● ● ●● ● ●●● ● ● ●●● ●● ● ● ●●●●● ● ●● ● ● ●
● ● ●
● ● ● ●● ●● ●
● ●●●● ●●●
●
● ● ●
● ●●● ● ● ● ● ●
● ● ● ● ● ●●● ●● ● ●●
● ●●●
● ●●● ● ● ●
● ● ● ● ● ● ● ●● ● ● ●
● ●●● ● ●● ● ● ●●
● ● ●
● ●● ● ● ● ●● ● ● ● ●
●● ● ● ●● ● ● ●● ●
● ● ● ●●
● ● ● ●● ● ● ● ● ● ● ● ●● ● ● ●● ● ●●● ●
●●● ● ● ● ●
● ● ● ● ●
●
● ● ● ●● ●●● ●● ● ● ●● ●
●● ●
●● ● ●● ●●● ● ● ● ●●● ● ●●● ●●● ●●
● ●● ● ●●
● ● ● ● ●
●● ● ●
● ● ● ●● ● ● ● ● ●
● ●
● ● ●●● ●
● ● ● ●● ● ● ● ●● ● ● ●● ● ●
●
● ●●
●● ● ●● ● ●● ●● ● ●
−1
● ● ● ● ●●● ●
● ●● ● ●● ● ● ● ● ● ●
● ● ● ● ● ●
●● ●●● ● ● ● ●● ●
● ●● ●● ●● ●
● ● ●
● ●● ●● ● ● ● ● ● ●
● ● ● ●●● ● ● ● ● ●● ● ●●
●
● ●● ● ● ●● ●
●
● ● ● ● ●●
● ● ●●
●
●●
● ● ● ●
● ● ● ● ●● ● ●
● ● ●● ● ● ●● ●
● ● ● ●● ●
● ● ● ● ●
● ●●
● ●●
● ● ● ●
● ● ● ● ● ●
−2
●●●
● ● ● ●
●
●
● ●
● ●
● ●
● ● ●
●
●
●
● ● ●
● ●
−3
−3 −2 −1 0 1 2 3
Correlation .25
4
●
3 ● ●
●
●
● ●
● ● ●
●
● ●
● ● ●
2
● ● ●
● ●● ●
●
● ● ● ●
●● ● ● ●● ● ● ● ● ● ● ● ●
●● ● ● ●● ● ●
● ● ●●
● ● ● ●● ● ●
●
● ● ●
● ● ● ● ● ●
● ●● ● ● ●●● ● ●
● ● ● ●
● ●
● ● ● ● ●
● ●● ●●● ● ●
● ●● ● ● ● ● ●
● ● ●●● ● ●●
● ● ●● ● ●
● ●●
● ● ●
●● ●● ● ● ● ● ●
●● ●
1
● ● ● ●● ● ● ● ● ●●
● ●● ● ● ● ●●● ●● ● ● ●●●
● ● ●
●● ● ● ● ● ● ● ● ● ●●
●● ●● ● ● ●● ● ● ●●● ● ● ●
● ●● ●
●●●●● ●●● ● ● ●● ● ●● ● ● ●
●
● ●● ● ●
●●●● ● ● ● ●●●
●
●
●
●
● ● ●● ● ● ●
● ● ●
● ● ●● ●● ● ● ●
● ● ●
●●●● ●● ●●●●●●● ●●●● ●● ● ● ●● ● ● ● ● ● ●
● ● ● ●●
●●
●●● ●●● ● ●●●●● ● ● ● ● ●●●
●
● ● ● ● ●● ●●
●● ● ● ●●
●●● ● ●
● ● ● ● ●● ● ● ● ●● ● ●● ●● ● ● ●
● ● ●● ● ● ●● ● ● ● ● ●
Z
● ● ● ● ● ●●● ●
● ● ●● ● ● ● ●● ● ● ● ● ● ● ●● ● ● ●●●● ●●
●
●
● ●●● ● ● ●
● ●● ● ● ● ● ●● ●●
●
●
● ● ● ●
● ●● ●● ● ● ● ●● ● ● ● ●●
● ●● ●
● ●● ● ●● ● ●● ● ● ● ● ●● ● ● ● ● ● ● ●
●● ●● ●●●●● ● ●●●
0
● ●
● ●
●●● ● ●● ●●●● ● ● ●
● ●
●
●● ●● ● ● ●●
●● ●
●●● ●● ●
●●● ● ● ●● ●● ● ●
● ●
● ● ● ● ● ● ● ●●
● ● ● ●
● ● ● ● ●
● ●● ●
● ● ●
●● ● ●● ● ●● ●●●●●● ●● ●● ● ●
●
● ●●● ● ●●
● ● ● ●
● ●● ● ●
●
●
●
●●●●●● ● ●●
●
●
●
●● ● ● ● ●●
● ● ●●● ●● ●● ● ●● ● ● ●● ●●● ●●●●● ●●●●
●
●●● ● ● ● ●
●
● ● ● ● ●● ● ● ●● ●●
●● ●● ● ● ●●
●
● ● ●
● ●● ●● ● ●● ● ●● ●● ●● ● ●● ● ● ● ● ●● ● ●● ● ●
●
●
● ● ● ● ● ● ● ●● ● ●● ● ● ●● ● ●●● ● ●● ● ● ●
●
●
● ●●●●● ● ●●● ●● ● ● ● ● ●
● ● ● ●● ●
● ● ● ● ● ● ● ● ●●● ● ●
● ●● ● ● ●●●
●●●● ● ●
−1
●
● ●● ●●● ●● ● ●●● ● ●●●● ● ● ● ●
●●
● ●
●
● ● ● ●● ● ●
● ● ● ●● ●● ●● ● ●
●● ●
● ● ● ●●
● ●● ●●● ●
●
● ●● ●●●
● ●
● ● ● ● ● ●● ●
● ● ● ●
● ● ●● ●
●●●
● ● ●
●
● ● ● ●
●●●●● ●
● ● ●
● ●●
●
● ● ● ● ●
● ●● ● ● ● ● ● ●
●● ● ● ●
●
● ● ●● ●● ● ● ●●
● ● ● ● ●●
● ●
● ●● ● ● ●●
● ●
● ● ●
● ● ●
● ●
−2
● ● ● ● ●
●
● ●
● ● ● ●
● ● ● ●
●
● ● ●
● ● ●
●
−3
−3 −2 −1 0 1 2 3
Correlation .5
● ●
● ●
3
●
●
● ● ●
●
● ●
● ● ●
● ●● ● ●
●
●● ● ● ●
● ● ● ●
● ● ● ● ● ●
●● ●● ●
● ●
2
● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ●
● ●
● ● ●● ●● ●● ● ● ●● ●
● ● ●● ● ●
● ●
●●
● ● ●● ● ● ●● ● ● ●
● ● ●
● ● ● ● ●● ●
● ● ● ●
● ●● ● ● ● ●● ●
● ● ● ● ●
●● ● ●● ● ●● ●● ●● ● ● ●
● ●●●● ● ● ●● ● ●●● ● ●● ● ●●
● ●
● ● ●
●
●● ● ● ● ● ● ●
● ● ● ● ●
● ● ●●● ●●●
● ● ● ● ●
● ● ● ● ● ●●● ●
●● ● ● ● ● ●● ●
1
● ●● ●
● ●● ●
●
● ● ●
● ● ●● ●
● ●● ● ●●● ● ● ●● ●● ● ● ● ● ●● ● ● ●
● ●● ● ●● ● ● ● ● ● ●●● ● ●
● ● ● ● ● ●● ●
● ●● ● ● ●●● ● ● ●● ●●
● ● ● ● ●● ● ●● ● ●●● ● ● ●
● ● ● ● ●
● ●● ● ● ● ● ● ●
● ● ● ●● ● ● ● ● ●●●●●
● ●● ● ●●●●●●●●
●● ●
●● ● ● ● ● ●● ●● ●●
●●
●● ● ●● ●●●
● ●● ● ● ●
●●●●● ●
● ●
● ●● ● ● ●● ● ● ● ● ● ●
● ●
●
● ● ● ● ●● ● ●● ● ● ● ●● ● ● ● ● ● ●
● ●● ●●● ● ●
●● ● ●●●●●● ●●●●●● ● ●●● ● ● ●●●●●
● ● ● ●● ● ● ●● ● ● ●● ● ●
● ●● ● ●●
Z
●
0
● ● ●
● ● ● ●● ● ● ● ●●●●
●●
● ● ●●●●● ●
● ● ●● ●
●
●
●●
●
● ●● ● ●
●●●
● ● ●● ●● ● ●● ● ●●
● ●● ●● ● ● ● ●●● ● ●
● ● ●
● ● ●
● ●● ● ● ● ●●
● ●●●● ● ●● ● ● ●● ● ● ● ●● ● ● ● ●
● ● ●● ● ●
● ●● ● ● ● ●● ●
●
● ●● ●● ●● ●●
● ●● ●● ● ● ● ●●●● ● ● ● ●● ● ● ●● ● ●
●
●● ●
● ● ● ● ● ● ●
●
●
●●●●● ●
●● ● ● ●●
● ● ● ●
● ●●● ● ● ● ● ●
● ●● ● ● ●● ●●● ●● ●● ● ● ● ● ● ● ●
●● ● ● ● ● ●● ● ● ● ● ●
●●● ● ● ●
● ●● ●
●● ● ●● ● ●● ● ● ●
● ● ●● ●
●
● ●●
● ●● ● ● ● ●● ● ●● ● ●● ●
●
● ● ●●● ● ● ●
● ● ● ●● ●● ● ● ● ● ●● ● ● ●●● ● ● ● ●● ●
−1
●● ● ●
●● ●●● ● ● ●●
●●● ● ●● ●● ● ● ● ● ●
● ● ● ● ●● ● ● ●● ● ● ● ●● ●●● ● ● ● ● ●
●●● ● ●● ● ●●
● ● ● ●● ● ● ● ● ● ●
● ● ● ●● ●●● ●● ●● ●
● ● ● ●● ● ● ● ●● ● ●
● ● ●
● ● ●
● ● ● ●
●● ● ● ●● ● ●
●● ● ● ●
● ● ●● ● ● ● ● ● ●●●● ● ● ●
●● ● ●●● ● ● ● ●
● ●
● ● ● ● ● ● ●
−2
● ●● ●●
●●● ● ●
● ● ●● ●●● ●
● ●
● ●
● ● ● ●
●
●●
●
● ● ●● ●
●
●
● ● ● ●
● ●
● ● ●
● ● ●
−3
●
● ●
● ●
●
●
−3 −2 −1 0 1 2 3
Correlation .75
4
● ●
● ●
● ●
●
● ●
●
●
●
●● ●●
●●●
● ●●
● ●● ● ● ●
●
● ●
● ● ● ●●● ●●
● ● ● ●● ● ● ● ● ●
● ● ● ● ●
●● ● ● ● ●● ● ● ●
● ●●● ● ● ● ● ●● ● ● ●
2
● ● ● ●
● ● ● ● ●●● ● ●● ● ●
●●●● ●● ● ●● ● ●●● ● ●●● ●●
● ● ● ●
●● ● ●●● ● ● ●● ● ● ●●
● ● ● ●●● ●●●● ●●●●●● ● ●● ●● ●● ●
● ●
● ●● ● ● ●
● ● ●●
● ●● ●●●● ●●
●● ● ● ● ● ● ●
● ● ●
●● ● ● ● ●● ●●●
●
● ●
● ● ●● ● ● ● ● ●
●
●● ●● ● ● ● ● ●●
●●● ●● ● ●● ●●● ● ●
● ●●● ● ●● ●● ●●●● ●●● ● ●
●● ● ●
● ● ●● ●●●
● ●● ● ●● ● ● ● ● ● ●●
●●
●
● ● ●● ●●●● ● ● ● ●●● ●●●● ●●● ●● ● ●● ● ●
● ●
●● ● ●● ●● ●● ●● ● ● ●● ●● ● ●
● ● ● ● ●● ● ●● ● ● ●● ● ● ●● ●
● ●
●● ●● ●● ●●● ●● ● ● ●● ● ●● ● ●
● ● ● ●
● ●● ● ● ●● ● ●●
●
●● ●
●
● ●●● ●●●
● ● ●● ●
● ● ● ● ● ●● ●● ● ● ● ● ● ●●● ●
● ● ● ●● ● ●●●●●●● ● ●●●
●
●●● ● ●● ●●●
●●● ●●●● ●● ●●● ●●● ●
●
● ●●●● ●
● ● ● ●● ● ●
●
0
● ●● ● ●● ● ●●
● ● ● ●
● ●
● ● ● ● ● ● ●
● ● ●● ●● ●● ●●● ●●
● ● ● ●● ●● ● ● ● ● ●
●● ●● ● ● ● ●●●● ●●●●● ● ● ● ●
● ●● ● ●
●● ● ●● ● ●● ● ●●●●●● ● ●
●● ●● ●
● ● ●
● ● ● ●● ● ●●●● ● ●●●●●
● ● ● ● ●● ● ●● ●
●
● ●● ● ●●● ●● ● ● ●●● ●● ● ● ●●
●● ● ● ● ●
Z
● ●● ●
●
●● ● ●
●● ●● ● ●●
● ● ●●●
●●●● ●● ● ●
● ●
● ● ●
●
●
● ●● ●
●● ● ●● ● ●●
●
● ●●
●●● ●● ● ●
● ● ●
● ●●
● ● ● ●●●● ●● ● ● ●●● ● ● ● ●●
● ●
●● ●● ● ● ● ● ●
● ● ● ●●● ● ●● ●
● ● ● ● ● ●● ● ●● ● ●● ●●●● ●● ●● ● ● ●
● ●
● ● ● ● ● ● ●● ●● ● ●● ●●● ● ● ●
● ● ● ● ●●●● ●● ● ● ●● ●●
● ●●●
● ● ●● ● ●●●● ● ● ●
●● ● ● ● ● ●
●●●● ● ● ● ●● ●
●●
●
● ●● ● ● ● ●
●● ● ● ● ●● ● ● ●
●● ●
●● ●● ●● ● ●
−2
● ● ●● ● ●●
● ● ● ● ● ●● ● ● ●● ●
● ● ●
●
●
● ● ● ● ● ●
● ● ● ●● ●
● ● ● ●
● ●
●● ● ● ● ● ● ●● ●●●
●● ● ● ● ●●
●
● ●● ● ●
● ●
● ● ●● ● ● ● ●●● ●
● ● ●
● ● ● ● ●
●
●● ● ●
● ● ●
●● ●
●
−4
● ● ●
●
●
●
●
−6
−3 −2 −1 0 1 2 3
Correlation .95
10
●
● ●
●
●
●
● ● ●
● ● ● ●
● ● ● ● ●
●
● ●
● ● ● ● ●
● ● ● ●
● ●
●● ●
● ● ●
● ●
● ●●● ●●● ●●
5
●● ● ● ●● ●
● ●● ● ● ●
● ●●●● ●●●● ●●●● ●
●● ● ● ● ● ●● ● ●●
●
● ●● ● ●●
●●
●●●●● ●
● ●●
● ● ●●● ●
●
●●●●●
● ●
● ● ●● ● ●
● ●● ●● ●●●●●●
●●
●●●●●●● ●● ● ●●
● ●●●● ●● ●● ●● ● ●
●● ●
● ● ● ● ●● ●
●
● ●● ● ●● ●
●● ●● ●
●●●●●●● ●●●●● ● ●
●● ●● ●
●●●●
●● ● ●
● ●● ●
● ● ●● ● ● ●●●●● ● ●● ●
●● ●●●●● ●● ●●●●●● ● ●● ●●●
● ●● ● ● ●● ● ●● ●●
●●●● ● ● ●●●● ● ●●●● ●●● ● ● ●
●● ●● ●● ● ●● ●
● ●● ●●●●●●●
●
● ●●● ● ● ●
●●● ●●●● ●●●●●●
●●● ● ●
● ●●●●
●
● ●
●
●●
●● ●●● ●●● ●●●
●● ● ●
● ●●● ●●●●●●● ●● ●
●●
● ●●●
● ● ●●
● ●●●●
● ● ●
● ● ●
● ● ●● ● ●● ●
●●● ●●●●●● ●● ●
● ●● ●●● ● ●●●
● ●● ●●
●● ● ●● ●
Z
●● ●●
● ●● ●●●● ●
● ●●●●●●● ●
●●●●● ● ●●●
●●● ●● ●
● ● ●
0
● ● ●● ●●●● ●● ●●●●
●● ●
●●●
● ●● ●●
●● ●● ● ●●
● ●● ●●
●
●
●
●● ●●●●●● ● ●
● ●●●
●● ●● ● ● ● ● ●
●●●● ● ● ●
●●●
●●●● ●●●●●●●●●● ● ●●
● ● ●
● ●● ●● ●
●●●●●●● ●●●●●
● ●●●● ●●●● ●
●
● ● ● ●● ●● ●●
●● ●
●
●●●●● ●●●
● ●●● ● ●●
● ●●● ●
● ●● ●●●
● ● ●● ●●
● ●●● ●●
●
●●●
● ● ●
●●
● ●● ●●●●
●●
● ●● ●● ●● ●●●● ●●●●
● ●● ●● ● ● ● ● ●
●● ● ●
●●●
●●●●●
●● ● ● ●● ●●
●●
●
●
●● ● ● ●● ●●●●●
●● ●● ●
●● ● ●●
●●
● ●●●●● ●
●● ● ● ● ●● ● ●● ●
● ● ●● ●
●●
● ●●● ● ● ●● ●● ● ● ● ● ●
●● ● ● ●●● ●● ● ●
● ●● ●● ● ●
● ●
●● ●● ●●● ● ● ● ●
●● ●●●●●●●● ●●●
● ●
● ●● ● ● ● ● ●●
● ●●
● ● ● ●● ●●●
●● ●●● ● ●
● ●●● ●●● ● ● ●●● ● ●
●● ● ●● ● ●● ● ●
−5
● ●●● ● ●● ●
● ● ● ●
● ● ●● ● ● ●
● ●● ●
●
● ● ● ● ● ●●
● ●
●
●●● ● ● ●
●
● ●●● ●
● ●
●● ● ● ●●
● ●
●●
●
−10
−3 −2 −1 0 1 2 3
50
●
40 ●
●●
●
●●
●●
●
●●●
● ●
●
30
●
●●
●●●
●●●
Y
● ●
●
●●
●
●
●
●●●●●
●● ●●●
●
●●
●●
20
● ●
●●●
●
●●
●●●
●● ●
●●●●
●
●●●
●●●
●● ● ●●
●● ●●●
●
●
●● ●●●●
●● ● ●●●
●
●
● ●
●
●
●
●●●
●●
●
●●●●
●●
●
●●●
● ●● ●●
● ●
●
●
●●●
●●●
10
●●● ●
●
●●●●●
● ●
●
●●●
●●
●●●●
●●●●
●
●● ●
●●
●
●●
●●
●● ●
●
●
●●●
●●●
●●
●
●●●●
● ●●
●
●
●
●
●
●
●
●
●●
●
●
●
●
●●
●● ●●●●
●
●
●●
●●●
●●
●●
●●●●●● ●●●
●●
●●
●
●●●●
●● ● ● ●●
●
●
●●
●●
●
●
● ●
●
●●
●
●●●
●● ●
●●
●
●● ●●●●●
●●
●
● ●●
●
●●
●●●●
●●●●●●●
●
●●
●
●
●●●
●●●●
●●●
●●●●
●●
●
●●●● ●
●● ● ● ● ● ● ●●●●
●●●
●● ●●●●●
●●●
●
●●●●●● ● ●●●
●
●
●●
●●
●
●●●
●
●
●●
●
●
●●
●
●
●
●
●●
●
●
●
●
●●
●●●
●● ●
●●
●
●●
●
●
●
●●●
●
● ●● ●●●
●●●●●●
● ●
●●
●
●●●
●●
●
●
●●●
●
●●
●●
●●
●●
●
●
●
●
●
●●
●
●
●●
●
●
●●
● ●●●
●
●● ●●●
●
●●●●
●●●
●●●
●●
●
● ●●●
●
●
●●●●
●●
●
●
●●
●●●
●
●
● ●
● ●
●
● ●●
●●
●●
● ●
●●
● ●
●
●
●●●●
●
●
● ●
●●●
●
●●
●
●
●●
●
●●
●
●
●●
●
●●
●●
●
●●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●
●
●●●
●
●●●
●
●●
●
●
●
●●●●●●
●
●●●
● ● ●● ●●●
●● ●● ● ●
0
●● ● ●
●●
●●● ●
●●
●●
●●●
●
●●
●
●●
● ●
●●●
●●
●●● ●
●
● ●●●● ●●
●
● ●
●●●
●
●●
●●
●
●●
●●
●●●
●●
●●●
●● ●●●● ● ●●
●
●
●●●●● ●
●
●●
−4 −2 0 2 4 6
15
10
Y
● OBS ●
●
●
RESIDUAL
5
●
●
●
FIT ●
●
●
0
2 4 6 8 10
Y = β0 + β1 X
Y = β0 + β1 X
β0 The intercept.
Y = β0 + β1 X
β0 The intercept.
β1 The slope.
Y = β0 + β1 X +
Y = β0 + β1 X +
Yi = β0 + β1 Xi + i
We will usually be working with a model for the error term:
i ∼ IID N(0, σ 2 )
P
(Xi − X )(Yi − Y )
β̂1 =
(Xi − X )2
P
β̂0 = Y − β̂1 (X )
In other words:
σy
β1 = ρ
σx
Conclusion: don’t use the correlation coefficient as a measure
of association unless the relationship is linear! The correlation
coefficient is just the slope of the line after both variables have
been standardized!
Because R 2 = 1 − RSS
TSS , it is also the proportion of variance
explained by the regression.