A tidier version of chisq.test() for goodness of fit tests and tests of independence.
chisq_test(x, formula, response = NULL, explanatory = NULL, ...)
x | A data frame that can be coerced into a tibble. |
---|---|
formula | A formula with the response variable on the left and the explanatory on the right. |
response | The variable name in |
explanatory | The variable name in |
... | Additional arguments for chisq.test(). |
# chisq test for comparing number of cylinders against automatic/manual mtcars %>% dplyr::mutate(cyl = factor(cyl), am = factor(am)) %>% chisq_test(cyl ~ am)#> Warning: Chi-squared approximation may be incorrect#> # A tibble: 1 x 3 #> statistic chisq_df p_value #> <dbl> <int> <dbl> #> 1 8.74 2 0.0126