使用 t 检验比较均值

R 中的数值数据推断

Mine Cetinkaya-Rundel

Associate Professor of the Practice, Duke University

更标准的薪酬度量

将比较年均 income 改为比较平均 hrly_rate

  • 假设一年 52 周
  • hrly_rate = income / (hrs_work * 52)
R 中的数值数据推断

研究问题与假设

数据是否提供了美国公民与非公民平均小时工资存在差异的有力证据?

设 $\mu =$ 平均小时工资

$H_0: \mu_{citizen} = \mu_{non-citizen}$

$H_A: \mu_{citizen} \ne \mu_{non-citizen}$

R 中的数值数据推断

汇总统计量

acs12 %>%
  filter(!is.na(hrly_rate)) %>%
  group_by(citizen) %>%
  summarise(x_bar = round(mean(hrly_rate), 2),
            s = round(sd(hrly_rate), 2),
            n = length(hrly_rate)) 
  citizen  x_bar      s   n
1 no       21.19  34.50  58
2 yes      18.52  24.73 901
R 中的数值数据推断

实施检验

t.test(hrly_rate ~ citizen, data = acs12, null = 0, 
       alternative = "two.sided")
  • 原假设:
    • $H_0: \mu_{citizen} = \mu_{non-citizen}$
    • $H_0: \mu_{citizen} - \mu_{non-citizen} = 0$ $\rightarrow$ null = 0
  • $H_A: \mu_{citizen} \ne \mu_{non-citizen}$ $\rightarrow$ alternative = "two.sided"
R 中的数值数据推断

实施检验

t.test(hrly_rate ~ citizen, data = acs12, null = 0, 
       alternative = "two.sided")
    Welch Two Sample t-test
data:  hrly_rate by citizen
t = 0.58058, df = 60.827, p-value = 0.5637
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -6.53483 11.88170
sample estimates:
 mean in group no mean in group yes 
         21.19494          18.52151 
R 中的数值数据推断

条件

  • 独立性:
    • 每个样本内的观测应彼此独立。
    • 两个样本之间应相互独立。
  • 样本量/偏度:原始数据越偏斜,为获得对称的抽样分布所需的样本量越大。

chp3-vid3-hrly-rate-citizen

R 中的数值数据推断

Passons à la pratique !

R 中的数值数据推断

Preparing Video For Download...