A tidier version of chisq.test() for goodness of fit tests and tests of independence.
Arguments
- 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. Alternatively, a - responseand- explanatoryargument can be supplied.
- response
- The variable name in - xthat will serve as the response. This is an alternative to using the- formulaargument.
- explanatory
- The variable name in - xthat will serve as the explanatory variable. This is an alternative to using the formula argument.
- ...
- Additional arguments for chisq.test(). 
See also
Other wrapper functions:
chisq_stat(),
observe(),
prop_test(),
t_stat(),
t_test()
Examples
# chi-squared test of independence for college completion
# status depending on one's self-identified income class
chisq_test(gss, college ~ finrela)
#> Warning: Chi-squared approximation may be incorrect
#> # A tibble: 1 × 3
#>   statistic chisq_df   p_value
#>       <dbl>    <int>     <dbl>
#> 1      30.7        5 0.0000108
# chi-squared goodness of fit test on whether self-identified
# income class follows a uniform distribution
chisq_test(gss,
           response = finrela,
           p = c("far below average" = 1/6,
                 "below average" = 1/6,
                 "average" = 1/6,
                 "above average" = 1/6,
                 "far above average" = 1/6,
                 "DK" = 1/6))
#> # A tibble: 1 × 3
#>   statistic chisq_df   p_value
#>       <dbl>    <dbl>     <dbl>
#> 1      488.        5 3.13e-103
