Skip to content

ENH: added chi^2 effect size in contingency table class, closes #6184 - #6598

Open
zhaobinlidev wants to merge 3 commits into
statsmodels:mainfrom
zhaobinlidev:chi2effsize
Open

zhaobinlidev wants to merge 3 commits into
statsmodels:mainfrom
zhaobinlidev:chi2effsize

Conversation

@zhaobinlidev

Copy link
Copy Markdown
Details

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in master and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/master -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

@coveralls

coveralls commented Mar 21, 2020 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0008%) to 87.654% when pulling a410860 on ZhaoBin-Li:chi2effsize into 8f77ce6 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member

Thanks for the PR

Avoid autoformatting code that is not related to the PR. It makes it difficult to see what changes are made if the PR has a lot of additional "cosmetic" changes.
It's not too bad in this case, so we can keep it, instead of redoing the PR.

question about attribute

effectsize is not important for internal followup computation, so we don't really need to chache it.

should it be a method?
Are there options or other definitions or cases for effect size in this case, so that it would be better to allow for keyword options?

I'm not familiar enough in this area to tell, but for t-test and anova, we would need to use options because there are variations in the definition of the effect sizes.
In that case, it would be better to add it as a method, so it can be extended in future.

@josef-pkt

Copy link
Copy Markdown
Member

@kshedden any comments to this kind of extensions?

@josef-pkt

Copy link
Copy Markdown
Member

related, since I'm looking at effect size for other statistics.

Is there a literature for confidence intervals of the effect size for this case?
If it is a method, then we could potentially return also the confidence interval as an option in that case.

I guess for future compatibility it should be a method even if we don't have any extensions right away.

@codecov

codecov Bot commented Mar 23, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #6598 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6598      +/-   ##
==========================================
- Coverage   85.28%   85.27%   -0.01%     
==========================================
  Files         646      646              
  Lines      103607   103624      +17     
  Branches    11270    11270              
==========================================
+ Hits        88358    88364       +6     
- Misses      12793    12805      +12     
+ Partials     2456     2455       -1
Impacted Files Coverage Δ
statsmodels/stats/contingency_tables.py 87.36% <100%> (+0.1%) ⬆️
statsmodels/stats/tests/test_contingency_tables.py 100% <100%> (ø) ⬆️
statsmodels/graphics/functional.py 79.04% <0%> (-5.24%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f77ce6...a410860. Read the comment docs.

@zhaobinlidev

Copy link
Copy Markdown
Author

Hi @josef-pkt,

I realize that using pd dataframes as unit testing break the code, so I have updated the code again.

Not sure about CIs around chi^2 effect size, though I certainly think is possible. The effect size could be extend as a method with options. For now I am putting effsize together with the p values and statistic under test_nominal_association because I think these concepts come together and make things neater. We could easily refactor the effect size as a method once we have more options.

Checked code with sphinx and pytest. Thank you.

Regards,
ZhaoBin

@zhaobinlidev

Copy link
Copy Markdown
Author

If needed, we could add effect size options to test_nominal_association, since the effect size I implement is particular to nominal tables

@bashtage bashtage modified the milestones: 0.12, 0.13 Aug 11, 2020
@josef-pkt josef-pkt modified the milestones: 0.13, 0.15 Dec 6, 2022
@josef-pkt

Copy link
Copy Markdown
Member

core change here looks good (ignoring pep-8 formatting changes)

I don't know or remember enough about other effect size definitions and options. We might need more specific names like effectsize_chi2.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chisquare_effectsize outputs array instead of scalar when probs1 and probs2 are two dimensional arrays

4 participants