평균으로의 회귀

R로 시작하는 회귀 분석

Richie Cotton

Data Evangelist

핵심 개념

  • 반응값 = 적합값 + 잔차
  • “설명한 부분” + “설명하지 못한 부분”
  • 잔차는 모델 한계와 근본적 무작위성 때문에 발생
  • 극단값은 종종 우연 때문
  • 평균으로의 회귀: 극단값은 시간이 지나 지속되지 않음
R로 시작하는 회귀 분석

피어슨의 부자 키 데이터셋

  • 아버지-아들 쌍 1078개
  • 키 큰 아버지에게 아들도 클까요?
father_height_cm son_height_cm
165.2 151.8
160.7 160.6
165.0 160.9
167.0 159.5
155.3 163.3
... ...
1 Adapted from https://www.rdocumentation.org/packages/UsingR/topics/father.son
R로 시작하는 회귀 분석

산점도

plt_son_vs_father <- ggplot(
  father_son, 
  aes(father_height_cm, son_height_cm)
) +
  geom_point() +
  geom_abline(color = "green", size = 1) +
  coord_fixed()

아들의 키 대 아버지의 키 산점도. 아버지와 아들의 키가 같을 때의 선이 표시됨. 아버지가 클수록 아들도 커집니다.

R로 시작하는 회귀 분석

회귀선 추가하기

plt_son_vs_father +
  geom_smooth(method = "lm", se = FALSE)

아들의 키 대 아버지의 키 산점도. 선형 추세선이 표시되어 있으며, 부자 키가 같을 때의 선보다 덜 가파릅니다.

R로 시작하는 회귀 분석

회귀 실행하기

mdl_son_vs_father <- lm(
  son_height_cm ~ father_height_cm, 
  data = father_son
)
Call:
lm(formula = son_height_cm ~ father_height_cm, data = father_son)

Coefficients:
     (Intercept)  father_height_cm  
          86.072             0.514
R로 시작하는 회귀 분석

예측 만들기

really_tall_father <- tibble(
  father_height_cm = 190
)
predict(mdl_son_vs_father, really_tall_father)
183.7
really_short_father <- tibble(
  father_height_cm = 150
)
predict(mdl_son_vs_father, really_short_father)
163.2
R로 시작하는 회귀 분석

연습해 봅시다!

R로 시작하는 회귀 분석

Preparing Video For Download...