向均值回归

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 改编自 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...