การพยากรณ์คะแนนการสอนจากอายุ

การสร้างโมเดลด้วยข้อมูลใน 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}$
  • สอดคล้องกับ $\epsilon$ จาก $y = f(\vec{x}) + \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

มาฝึกกันเถอะ!

การสร้างโมเดลด้วยข้อมูลใน Tidyverse

Preparing Video For Download...