Skip to content

ENH: exact test equality of two proportions rebased - #6676

Open
josef-pkt wants to merge 3 commits into
statsmodels:mainfrom
josef-pkt:proportion_exact_rebased
Open

josef-pkt wants to merge 3 commits into
statsmodels:mainfrom
josef-pkt:proportion_exact_rebased

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

rebased version of #2608 from 2015

no merge conflict, no extra changes

@pep8speaks

Copy link
Copy Markdown

Hello @josef-pkt! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 85:1: E402 module level import not at top of file

Line 9:1: F401 'numpy as np' imported but unused
Line 10:1: F401 'scipy.stats' imported but unused

pt = ExactTwoProportion(yo1, n1, yo2, n2)

print(pt.chisquare_proportion_indep(yo1, yo2))
print(pt.chisquare_proportion_indep(yo1, yo2, alternative='todo'))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funny alternative

if alternative == '2-sided':
pvalue = stats.chi2.sf(stat, 1)
else:
pvalue = stats.norm.sf(stat)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use zstat_generic ?

If None, then the default method is used, currently a grid.
If int, then the integer specifies the number of grid points.
If grid is a tuple, then either the values are integers for linspace or
('bb', alpha, n_points) for Berger, Boos limitats for the maximum.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Berger-Boos looks a bit hidden with this interface


This is an exact pvalue and maintains and guarantees the size.

`grid` argument is currently not used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sentence looks outdated

pvm_ind = res[:,1].argmax(0)
pval = np.clip(res[pvm_ind, 1] + bb_correct, 0, 1)

return pval, res[pvm_ind, 0], pvm_ind, res

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Holder instance

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.03%) to 87.728% when pulling f277a25 on josef-pkt:proportion_exact_rebased into 5dea830 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

I'm not sure I can merge this PR with just a few changes. I don't remember enough, especially what structure we would need for future enhancements. What other cases does this need to handle in future?

Code looks overall fine as experimental version. unit tests against article and Berger-Boos website.
Module is private, and currently no "public" function.

currently only equality hypothsis "Tests for equality of two independent proportions"
Can this be extended to a value hypothesis?

I guess this could be extended to call other test statistics function for the base statistic that defines the rejection region. Then we could define "exact" p-values for any two-sample proportion test.

Too much work (especially, I don't want to go through the literature right now)
Cleanup and merge

@josef-pkt

josef-pkt commented Mar 22, 2022 •

Copy link
Copy Markdown
Member Author

In poisson we have etest included in the main function

we can do the same here
keep the implementation in this PR private and provide the test through the common test_xxx interface.
Then I don't have to decide on a relatively stable API for the part in here.

I implemented poisson etest in a simpler way using just a function instead of using a class as in here

IIRC: the "exact" version here is max and BB, (i.e. sup over nuisance parameter)
We don't have an "e-test" equivalent that uses constraint mle for nuisance parameter.
(so etest is simpler than the ones in here)

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.

3 participants