You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
chisquare_effectsize outputs array instead of scalar when probs1 and probs2 are two dimensional arrays #6184
GofChisquarePower chisquare_effectsize outputs a two element array instead of scalar when probs1 and probs2 are two dimensional arrays. It should output a numpy float. The problem seems to be the .sum(axis) on line 482. axis needs to be removed.
Output of import statsmodels.api as sm; sm.show_versions()
Details
[paste the output of import statsmodels.api as sm; sm.show_versions() here below this line]
import statsmodels.api as sm; sm.show_versions()
INSTALLED VERSIONS
Python: 3.7.4.final.0
OS: Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
AFAIR, this was intentional to vectorize the test, i.e. apply several similar tests at the same time
I assume what you want is to use probs0.ravel(), probs1.ravel() to compute it for the flattened data, is it? That's what removing the axis in sum would do. axis=None would be equivalent, but I don't know if we ever verified that case.
We never flatten data in statsmodels because it's most of the time wrong in statistical applications.
@josef-pkt: I'm not quite sure I understand. Typically the probabilities are in an n x m matrix where either each row or each column sum to one, depending on how you've oriented your matrix. In the documentation for this function the axis variable seems to be the thing that allows you to define the orientation of the data, and this seems to be what it is doing in the code. However, if you input a 2x2 matrix in then the following line will result in a two element vector instead of the expected scalar:
d2 = ((probs1 - probs0)**2 / probs0).sum(axis)
Removing the axis argument would solve that problem.
If I'm wrong, and instead it is expected that probs0 and probs1 are vectors then I don't understand what is being calculated, since the probabilities of such a vector should add up to two, not one...
On Mon, Oct 7, 2019 at 4:37 PM Alex ***@***.***> wrote:
@josef-pkt <https://github.com/josef-pkt>: I'm not quite sure I
understand. Typically the probabilities are in an n x m matrix where either
each row or each column sum to one, depending on how you've oriented your
matrix. In the documentation for this function the axis variable seems to
be the thing that allows you to define the orientation of the data, and
this seems to be what it is doing in the code. However, if you input a 2x2
matrix in then the following line will result in a two element vector
instead of the expected scalar:
I'm not sure I understand your case where probabilities are 2-D n x m.
d2 = ((probs1 - probs0)**2 / probs0).sum(axis)
Removing the axis argument would solve that problem.
If I'm wrong, and instead it is expected that probs0 and probs1 are
vectors then I don't understand what is being calculated, since the
probabilities of such a vector should add up to two, not one...
Or am I way off?
Probabilities for a simple comparison are 1 dimensional, e.g. flatten a 2x2
contingency table for observed and expected probabilities.
In the vectorized version we have several 1 dimensional comparisons, e.g.
one is the control and we have several treatments. We want to compare each
treatment to the control. A similar example would be all pairwise
comparisons across treatments.
To compute this multiple comparison in one vectorized solution, we can
stack the treatment probabilities so that each row (or column) represents
one treatment, then we compare each of them to the control.
So each row (or column) is normalized to sum to 1 to allow for counts as
inputs.
For the hypothesis test we would have to do in general a multiple
comparison p-value correction.
`axis=None` in numpy reduce operations flattens the array, so that should
be equivalent to flattening the input by the user.
I'm not sure there are unit tests for that case, I guess not.
Josef
Looking the the usage of axis in the code:
I think there is a bug if axis = 1, some keepdim are missing.
Josef
On Tue, Oct 8, 2019 at 2:06 PM Josef Perktold <[email protected]>
wrote:
On Mon, Oct 7, 2019 at 4:37 PM Alex ***@***.***> wrote:
> @josef-pkt <https://github.com/josef-pkt>: I'm not quite sure I
> understand. Typically the probabilities are in an n x m matrix where
either
> each row or each column sum to one, depending on how you've oriented your
> matrix. In the documentation for this function the axis variable seems to
> be the thing that allows you to define the orientation of the data, and
> this seems to be what it is doing in the code. However, if you input a
2x2
> matrix in then the following line will result in a two element vector
> instead of the expected scalar:
>
I'm not sure I understand your case where probabilities are 2-D n x m.
> d2 = ((probs1 - probs0)**2 / probs0).sum(axis)
>
> Removing the axis argument would solve that problem.
>
> If I'm wrong, and instead it is expected that probs0 and probs1 are
> vectors then I don't understand what is being calculated, since the
> probabilities of such a vector should add up to two, not one...
>
> Or am I way off?
>
Probabilities for a simple comparison are 1 dimensional, e.g. flatten a 2x2
contingency table for observed and expected probabilities.
In the vectorized version we have several 1 dimensional comparisons, e.g.
one is the control and we have several treatments. We want to compare each
treatment to the control. A similar example would be all pairwise
comparisons across treatments.
To compute this multiple comparison in one vectorized solution, we can
stack the treatment probabilities so that each row (or column) represents
one treatment, then we compare each of them to the control.
So each row (or column) is normalized to sum to 1 to allow for counts as
inputs.
For the hypothesis test we would have to do in general a multiple
comparison p-value correction.
`axis=None` in numpy reduce operations flattens the array, so that should
be equivalent to flattening the input by the user.
I'm not sure there are unit tests for that case, I guess not.
Josef
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#6184?email_source=notifications&email_token=AADLTH5T5ZVYVIYYHHEA2U3QNOMYVA5CNFSM4I5VDUJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEARXCAY#issuecomment-539193603
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AADLTHYHEJWTUWELAYRXSJLQNOMYVANCNFSM4I5VDUJA
>
> .
>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6184?email_source=notifications&email_token=AADLTH53VTREI256WVO6BHLQNTD4FA5CNFSM4I5VDUJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAVCTFI#issuecomment-539634069>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADLTH6EEVSXQQXCMQ3QM3LQNTD4FANCNFSM4I5VDUJA>
.
Technically, as Alex or josef have stated, we could calculate the chisquare_effectsize for 2 x 2 by using .ravel() removing the axis in line 480, chisquare_effectsize in gof.py
d2 = ((probs1 - probs0)**2 / probs0).sum()
Since chisquare_effectsize is in the gof (goodness of fit) module, perhaps we should have a separate effect size for chi square contingency test (implemented in statsmodels.stats.proportion.proportions_chisquare) with effect sizes of phi (for 2 x 2) and Cramer's V (for larger than 2 x 2)
Can you write a function and unit tests for the effect size equivalent to the statsmodels.stats.proportion.proportions_chisquare ?
It could delegate to chisquare_effectsize if that makes sense.
There are also the contingency table classes where it might be possible to add the relevant effect sizes as methods.
I don't have an overview in this area right now.
I'm currently stuck in and confused again about effect size definitions for versions of oneway anova.
general issue about adding effect size measures #5896
Sure, please assign the issue to me. Will be my 1st time contributing to statsmodel (or to open source) and I will go through the contributing guidelines. Coding up shouldn't be an issue
The main setup cost is setting up the dev environment, check out the source and compile.
If that's currently too much of a detour for you, then you could write the functions and unit test in a script file and I add them to a PR (with you as author).
I have added the effect size functionality in the contingency table class together with the unit tests and added documentation to the docs/source/contingency_tables.rst.
I saw that we also have to add the new functionality to the release notes of the upcoming version. The latest release notes is docs/source/release/version0.11.rst, which has already been released. Where do I get the release notes of the upcoming version?
I am also running make html which generates the documentation in docs/build/html. The documentation is not on the original statsmodel github. Do I commit the whole documentation to the pull request?
I am quite puzzled about compiling, since python is an interpreted program. I am running the effect size and the unit tests alright by importing the statsmodel module. How do I compile the program?
We don't have release notes for the next release yet. We will have to create one. You could add a sentence or paragraph to the PR comments, that can be copied when we have the release notes.
Doc build is automatic for dev, and will be updated for stable after the next release. There is nothing to add related to docs for a PR.
We mainly build the docs locally to check for mistakes. But we also get the results from the doc build on our CI testing.
compiling:
I usually use python setup.py build_ext --inplace for the dev environment in my git checkout folder,
That requires that cython is installed and a C compiler is available.
C compiler depends on operating system.
Hi @josef-pkt, I realized that I wrote unit tests only on numpy contingency tables. Will write them on pandas dataframe tables and commit again. Thanks
Activity
josef-pkt commentedon Oct 5, 2019
AFAIR, this was intentional to vectorize the test, i.e. apply several similar tests at the same time
I assume what you want is to use
probs0.ravel(), probs1.ravel()to compute it for the flattened data, is it? That's what removing the axis in sum would do.axis=Nonewould be equivalent, but I don't know if we ever verified that case.We never flatten data in statsmodels because it's most of the time wrong in statistical applications.
AlexGroves commentedon Oct 7, 2019
@josef-pkt: I'm not quite sure I understand. Typically the probabilities are in an n x m matrix where either each row or each column sum to one, depending on how you've oriented your matrix. In the documentation for this function the
axisvariable seems to be the thing that allows you to define the orientation of the data, and this seems to be what it is doing in the code. However, if you input a 2x2 matrix in then the following line will result in a two element vector instead of the expected scalar:Removing the
axisargument would solve that problem.If I'm wrong, and instead it is expected that
probs0andprobs1are vectors then I don't understand what is being calculated, since the probabilities of such a vector should add up to two, not one...Or am I way off?
josef-pkt commentedon Oct 8, 2019
josef-pkt commentedon Oct 8, 2019
zhaobinlidev commentedon Mar 16, 2020
Technically, as Alex or josef have stated, we could calculate the chisquare_effectsize for 2 x 2 by using .ravel() removing the axis in line 480, chisquare_effectsize in gof.py
d2 = ((probs1 - probs0)**2 / probs0).sum()Since chisquare_effectsize is in the gof (goodness of fit) module, perhaps we should have a separate effect size for chi square contingency test (implemented in statsmodels.stats.proportion.proportions_chisquare) with effect sizes of phi (for 2 x 2) and Cramer's V (for larger than 2 x 2)
Thanks for your consideration
Regards,
ZhaoBin
josef-pkt commentedon Mar 16, 2020
@zhaobin-li
Can you write a function and unit tests for the effect size equivalent to the
statsmodels.stats.proportion.proportions_chisquare?It could delegate to
chisquare_effectsizeif that makes sense.There are also the contingency table classes where it might be possible to add the relevant effect sizes as methods.
I don't have an overview in this area right now.
I'm currently stuck in and confused again about effect size definitions for versions of oneway anova.
general issue about adding effect size measures
#5896
zhaobinlidev commentedon Mar 17, 2020
Hi Josef,
Sure, please assign the issue to me. Will be my 1st time contributing to statsmodel (or to open source) and I will go through the contributing guidelines. Coding up shouldn't be an issue
Regards,
ZhaoBin
josef-pkt commentedon Mar 17, 2020
The main setup cost is setting up the dev environment, check out the source and compile.
If that's currently too much of a detour for you, then you could write the functions and unit test in a script file and I add them to a PR (with you as author).
zhaobinlidev commentedon Mar 19, 2020
Thanks Josef, I will give a try and if needed will get your help to add
zhaobinlidev commentedon Mar 21, 2020
Hi @josef-pkt,
I have added the effect size functionality in the contingency table class together with the unit tests and added documentation to the docs/source/contingency_tables.rst.
I saw that we also have to add the new functionality to the release notes of the upcoming version. The latest release notes is docs/source/release/version0.11.rst, which has already been released. Where do I get the release notes of the upcoming version?
I am also running make html which generates the documentation in docs/build/html. The documentation is not on the original statsmodel github. Do I commit the whole documentation to the pull request?
I am quite puzzled about compiling, since python is an interpreted program. I am running the effect size and the unit tests alright by importing the statsmodel module. How do I compile the program?
Thank you.
Regards,
ZhaoBin
josef-pkt commentedon Mar 21, 2020
@zhaobin-li Thanks
We don't have release notes for the next release yet. We will have to create one. You could add a sentence or paragraph to the PR comments, that can be copied when we have the release notes.
Doc build is automatic for dev, and will be updated for stable after the next release. There is nothing to add related to docs for a PR.
We mainly build the docs locally to check for mistakes. But we also get the results from the doc build on our CI testing.
compiling:
I usually use
python setup.py build_ext --inplacefor the dev environment in my git checkout folder,That requires that cython is installed and a C compiler is available.
C compiler depends on operating system.
ENH: added chi^2 effect size in contingency table class, closes stats…
zhaobinlidev commentedon Mar 21, 2020
Josef thanks for your support, I have done so and submitted a PR
ENH: added chi^2 effect size in contingency table class (corrected do…
zhaobinlidev commentedon Mar 21, 2020
Hi @josef-pkt, I realized that I wrote unit tests only on numpy contingency tables. Will write them on pandas dataframe tables and commit again. Thanks
ENH: added chi^2 effect size in contingency table class (corrected pd),