Inference for Numerical Data in R
Mine Cetinkaya-Rundel
Associate Professor of the Practice, Duke University
Instead of comparing average annual income
, compare average hrly_rate
:
hrly_rate = income / (hrs_work * 52)
Do the data provide convincing evidence of a difference between the average hourly rate of citizens and non-citizens in the US?
Let $\mu = $ average hourly pay
$H_0: \mu_{citizen} = \mu_{non-citizen}$
$H_A: \mu_{citizen} \ne \mu_{non-citizen}$
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
t.test(hrly_rate ~ citizen, data = acs12, null = 0,
alternative = "two.sided")
null = 0
alternative = "two.sided"
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
Inference for Numerical Data in R