Skip to content

Add function for chi square. - #701

Open
elinw wants to merge 2 commits into
easystats:mainfrom
elinw:chisq
Open

Add function for chi square.#701
elinw wants to merge 2 commits 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

@elinw

elinw commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the delay in responding, I was away on vacation for a few weeks, will think about the comments.
My main idea, though, is have the caption (that is be able to print the table with the chi square). I was thinking that it would be like some of the other data_* methods.

@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.01%. Comparing base (89daeba) to head (350e930).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
R/data_chisq.R 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #701      +/-   ##
==========================================
- Coverage   92.09%   92.01%   -0.08%     
==========================================
  Files          76       77       +1     
  Lines        7727     7778      +51     
==========================================
+ Hits         7116     7157      +41     
- Misses        611      621      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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