I need some help writing a simple function. I'm guessing this involves some use of tidyeval (which I have completely forgotten since the last time i had to use it), and I'm sort of in a hurry so any help would be greatly appreciated!
mtcars as an example:
library(infer)
library(dplyr)
d_hat <- mtcars %>%
mutate(vs = if_else(vs == 1, "one", "zero")) %>%
specify(disp~vs) %>%
calculate(stat = "diff in means", order = c("zero", "one"))
mtcars %>%
mutate(vs = if_else(vs == 1, "one", "zero")) %>%
specify(disp~vs) %>%
hypothesize(null = "independence") %>%
generate(reps = 5000, type = "permute") %>%
calculate(stat = "diff in means", order = c("zero", "one")) %>%
get_pvalue(obs_stat = d_hat, direction = "two_sided")
#> # A tibble: 1 x 1
#> p_value
#> <dbl>
#> 1 0
If I want to get p-values for other variables than disp I could of course just repeat everything and change disp, but I'd prefer a basic function that just allows me to change the input to specify.