用于解释的建模背景

Tidyverse 的数据建模

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

课程概览

  1. 建模导论:理论与术语
  2. 回归:
    • 简单线性回归
    • 多元回归
  3. 模型评估
Tidyverse 的数据建模

通用建模框架公式

$$

$$y = f(\vec{x}) + \epsilon$$

其中:

  • $y$:关注的结果变量
  • $\vec{x}$:解释/预测变量
  • $f()$:$y$ 与 $\vec{x}$ 的关系函数,亦称"信号"
  • $\epsilon$:非系统误差,亦称"噪声"
Tidyverse 的数据建模

两种建模情境

建模目的:

  • 解释:$\vec{x}$ 为"解释变量"
  • 预测:$\vec{x}$ 为"预测变量"
Tidyverse 的数据建模

用于解释的建模示例

德克萨斯大学奥斯汀分校关于教学评价分数的研究(见 openintro.org)。

问题:能否基于教师属性解释教学评价分数的差异?

变量:

  • $y$:基于学生评价的平均教学 score
  • $\vec{x}$:rankgenderagebty_avg 等属性
Tidyverse 的数据建模

用于解释的建模示例

来自 moderndive 包(ModernDive.com):

library(dplyr)
library(moderndive)
glimpse(evals)
Observations: 463
Variables: 13
$ ID           <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
$ score        <dbl> 4.7, 4.1, 3.9, 4.8, 4.6, 4.3...
$ age          <int> 36, 36, 36, 36, 59, 59, 59, 51...
$ bty_avg      <dbl> 5.000, 5.000, 5.000, 5.000...
$ gender       <fct> female, female, female, female...
...
Tidyverse 的数据建模

探索性数据分析

探索性数据分析(EDA)的三步:

  1. 查看数据
  2. 可视化数据
  3. 计算汇总统计量
Tidyverse 的数据建模

探索性数据分析

library(ggplot2)
ggplot(evals, aes(x = score)) +
  geom_histogram(binwidth = 0.25) + 
  labs(x = "teaching score", y = "count")
Tidyverse 的数据建模

探索性数据分析

Tidyverse 的数据建模

探索性数据分析

# Compute mean, median, and standard deviation
evals %>%
  summarize(mean_score = mean(score), 
            median_score = median(score),
            sd_score = sd(score))
# A tibble: 1 x 3
  mean_score median_score sd_score
       <dbl>        <dbl>    <dbl>
1       4.17          4.3    0.544
Tidyverse 的数据建模

让我们练习吧!

Tidyverse 的数据建模

Preparing Video For Download...