# calculate a null distribution of hours worked per week under
# the null hypothesis that the mean is 40
gss %>%
specify(response = hours) %>%
hypothesize(null = "point", mu = 40) %>%
generate(reps = 200, type = "bootstrap") %>%
calculate(stat = "mean")
# calculate the corresponding observed statistic
gss %>%
specify(response = hours) %>%
calculate(stat = "mean")
# calculate a null distribution assuming independence between age
# of respondent and whether they have a college degree
gss %>%
specify(age ~ college) %>%
hypothesize(null = "independence") %>%
generate(reps = 200, type = "permute") %>%
calculate("diff in means", order = c("degree", "no degree"))
# calculate the corresponding observed statistic
gss %>%
specify(age ~ college) %>%
calculate("diff in means", order = c("degree", "no degree"))
# some statistics require a null hypothesis
gss %>%
specify(response = hours) %>%
hypothesize(null = "point", mu = 40) %>%
calculate(stat = "t")
# more in-depth explanation of how to use the infer package
if (FALSE) {
vignette("infer")
}
Run the code above in your browser using DataLab