# NOT RUN {
# Permutations to create a simulation-based null distribution for
# one numerical response and one categorical predictor
# using t statistic
mtcars %>%
dplyr::mutate(am = factor(am)) %>%
specify(mpg ~ am) %>% # alt: response = mpg, explanatory = am
hypothesize(null = "independence") %>%
generate(reps = 100, type = "permute") %>%
calculate(stat = "t", order = c("1", "0")) %>%
visualize(method = "simulation") #default method
# Theoretical t distribution for
# one numerical response and one categorical predictor
# using t statistic
mtcars %>%
dplyr::mutate(am = factor(am)) %>%
specify(mpg ~ am) %>% # alt: response = mpg, explanatory = am
hypothesize(null = "independence") %>%
# generate() is not needed since we are not doing simulation
calculate(stat = "t", order = c("1", "0")) %>%
visualize(method = "theoretical")
# Overlay theoretical distribution on top of randomized t-statistics
mtcars %>%
dplyr::mutate(am = factor(am)) %>%
specify(mpg ~ am) %>% # alt: response = mpg, explanatory = am
hypothesize(null = "independence") %>%
generate(reps = 100, type = "permute") %>%
calculate(stat = "t", order = c("1", "0")) %>%
visualize(method = "both")
# }
Run the code above in your browser using DataLab