나이로 강의 점수 설명하기

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로 하는 데이터 모델링

회귀선의 기울기와 절편 계산

$\hat{y}= \hat{f}(\vec{x})$에 해당하는 y ~ 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...