rstatix icon indicating copy to clipboard operation
rstatix copied to clipboard

chisq_test() does not appear to accept piped data

Open jzadra opened this issue 4 years ago • 5 comments

chisq_test() seems to only expect a table. Since the goal of the package is to work with pipes, it seems like this is counterintuitive:

require(tidyverse)
#> Loading required package: tidyverse

diamonds %>% rstatix::chisq_test(cut, clarity)
#> Error in as.list.environment(environment()): object 'clarity' not found

diamonds %>% table(cut, clarity) %>% rstatix::chisq_test(cut, clarity)
#> Error in table(., cut, clarity): object 'clarity' not found

table(diamonds$cut, diamonds$clarity) %>% rstatix::chisq_test(cut, clarity)
#> Error in as.list.environment(environment()): object 'clarity' not found

table(diamonds$cut, diamonds$clarity) %>% rstatix::chisq_test()
#> # A tibble: 1 x 6
#>       n statistic     p    df method          p.signif
#> * <int>     <dbl> <dbl> <int> <chr>           <chr>   
#> 1 53940     4391.     0    28 Chi-square test ****

Created on 2020-05-05 by the reprex package (v0.3.0)

jzadra avatar May 05 '20 18:05 jzadra

Ah - came to ask the exact some question. @kassambara are we missing something fundamental in chisq_test()?

brentocarrigan avatar Sep 07 '20 22:09 brentocarrigan

Yup, me too :-) It essentially works like a standard chisq.test?

kilojarek avatar Nov 01 '20 22:11 kilojarek

Looks like it's exactly the same as chisq.test()

Si-Thu-Thein avatar Nov 25 '20 19:11 Si-Thu-Thein

l just wanted to add to others that it would be great to see this working as expected!

MattMcMullen avatar Mar 30 '21 16:03 MattMcMullen

I would also like this feature. I can only seem to make it work inside summarise() + unnest()

library(tidyverse)
library(rstatix)

diamonds |> 
  summarise(pval = chisq_test(cut, clarity)) |> 
  unnest(pval)

# vs 
diamonds |> 
  kruskal_test(price ~ clarity)

rjake avatar Jan 28 '22 03:01 rjake