Skip to content

Add function for chi square. - #701

Open
elinw wants to merge 1 commit into
easystats:mainfrom
elinw:chisq
Open

Add function for chi square.#701
elinw wants to merge 1 commit into
easystats:mainfrom
elinw:chisq

Conversation

@elinw

@elinw elinw commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This function follows the pattern in the documentation, and I found it useful to create it for my students. It might be good to let it make a caption the way that the means_by_groups() has the ANOVA results.

@strengejacke

Copy link
Copy Markdown
Member

You may take a look at the effectsize package where you can calculate lots of effect sizes from different R objects.

@strengejacke

Copy link
Copy Markdown
Member

Ok, I see the intention of this function. Maybe it's better to implement a chisq.test.dwtable() method instead? @etiennebacher wdyt?

@etiennebacher

etiennebacher commented Jul 27, 2026

Copy link
Copy Markdown
Member

Personally I don't really see the need for this function, it seems to simply replace a call to as.table() and lapply()? I get that it makes it easier for students but we also can't implement a function for all possible computations one could do on a table.

library(datawizard)

### Without data_chisq()
suppressWarnings({
  orig <- head(mtcars) |> 
    data_tabulate() |> 
    as.table() |> 
    lapply(stats::chisq.test)
})

### With data_chisq()
suppressWarnings({
  new <- head(mtcars) |> 
    data_tabulate() |> 
    data_chisq()
})

identical(orig, new)
#> [1] TRUE

Maybe it's better to implement a chisq.test.dwtable() method instead?

I would be in favor of adding this as a method, but chisq.test() isn't generic:

sloop::is_s3_generic("chisq.test")
#> [1] FALSE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants