年齢による教育スコアの説明

tidyverse で学ぶモデリング

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

復習:探索的データ可視化

tidyverse で学ぶモデリング

回帰直線

# Code to create scatterplot
ggplot(evals, aes(x = age, y = score)) +
  geom_point() + 
  labs(x = "age", y = "score", 
       title = "Teaching score over age")

# Add a "best-fitting" line ggplot(evals, aes(x = age, y = score)) + geom_point() + labs(x = "age", y = "score", title = "Teaching score over age") + geom_smooth(method = "lm", se = FALSE)
tidyverse で学ぶモデリング

回帰直線

tidyverse で学ぶモデリング

復習:モデリングの基本

  • 真の関係: モデルは $y = f(\vec{x}) + \epsilon$ と仮定
  • 目標: $y$ と $\vec{x}$ が与えられたとき、$f(\vec{x})$ を近似するモデル $\hat{f}(\vec{x})$ を適合させる。$\hat{y} = \hat{f}(\vec{x})$ は観測値 $y$ に対するフィット/予測値
tidyverse で学ぶモデリング

単純線形回帰によるモデリング

  • 真の関係:
    • $f(x) = \beta_0 + \beta_1 \cdot x$ と仮定
    • 観測値 $y = f(x) + \epsilon = \beta_0 + \beta_1 \cdot x + \epsilon$
  • フィット値:
    • $\hat{f}(x) = \hat{\beta}_0 + \hat{\beta}_1 \cdot x$ と仮定
    • フィット/予測値 $\hat{y} = \hat{f}(x) = \hat{\beta}_0 + \hat{\beta}_1 \cdot x$
tidyverse で学ぶモデリング

回帰直線の再確認

フィットされた青い回帰直線の式: $\hat{y} = \hat{f}(\vec{x}) = \hat{\beta}_0 + \hat{\beta}_1 \cdot x$

tidyverse で学ぶモデリング

回帰直線の傾きと切片の計算

y ~ x の形式の式を使用:

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

# Output contents model_score_1
Call:
lm(formula = score ~ age, data = evals)

Coefficients:
(Intercept)          age  
   4.461932    -0.005938
tidyverse で学ぶモデリング

回帰直線の傾きと切片の計算

y ~ x の形式の式を使用($\hat{y}= \hat{f}(\vec{x})$ に相当):

# 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...
  <chr>        <dbl>     <dbl>     <dbl>   <dbl>... 
1 intercept    4.46      0.127     35.2    0...
2 age         -0.006     0.003     -2.31   0.021...
tidyverse で学ぶモデリング

練習しましょう!

tidyverse で学ぶモデリング

Preparing Video For Download...