用年龄预测教学评分

Tidyverse 的数据建模

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

回顾:回归线

Tidyverse 的数据建模

新教师的预测

Tidyverse 的数据建模

回顾:回归表

library(ggplot2)
library(dplyr)
library(moderndive)

# Fit regression model using formula of form: y ~ x
model_score_1 <- lm(score ~ age, data = evals)

# Output regression table using wrapper function
get_regression_table(model_score_1)
# A tibble: 2 x 7
  term      estimate std_error statistic p_value lower_ci...
  <chr>        <dbl>     <dbl>     <dbl>   <dbl>    <dbl>...
1 intercept    4.46      0.127     35.2    0        4.21...
2 age         -0.006     0.003     -2.31   0.021   -0.011...
Tidyverse 的数据建模

预测值

  • 一般预测回归模型:$\hat{y} = \hat{f}(x) = \hat{\beta}_0 + \hat{\beta}_1 \cdot x$
  • 本模型:$\hat{\text{score}} = 4.46 - 0.006 \cdot \text{age}$
  • 我们的预测:$4.46 - 0.006 \cdot 40 = 4.22$
Tidyverse 的数据建模

预测误差

Tidyverse 的数据建模

预测误差

Tidyverse 的数据建模

将残差视为模型误差

  • 残差 = $y - \hat{y}$
  • 对应于 $y = f(\vec{x}) + \epsilon$ 中的 $\epsilon$
  • 我们示例教师:$y - \hat{y} = 3.5 - 4.22 = -0.72$
  • 在线性回归中,其平均为 0。
Tidyverse 的数据建模

计算所有预测值

# Fit regression model using formula of form: y ~ x
model_score_1 <- lm(score ~ age, data = evals)

# Get information on each point get_regression_points(model_score_1)
# A tibble: 463 x 5
      ID score   age score_hat residual
   <int> <dbl> <dbl>     <dbl>    <dbl>
 1     1   4.7    36      4.25    0.452
 2     2   4.1    36      4.25   -0.148
 3     3   3.9    36      4.25   -0.348
 4     4   4.8    36      4.25    0.552
 5     5   4.6    59      4.11    0.488
Tidyverse 的数据建模

"最佳拟合"的回归线

Tidyverse 的数据建模

Vamos praticar!

Tidyverse 的数据建模

Preparing Video For Download...