Repository navigation
Conversation
|
Bug ? trying some corner cases These two pvalues should be the same. The second agrees with Berger's web application. |
|
The only possible explanation I can come up with is floating point precision. We calculate pvalue with strict inequality of floating point numbers which might get messed up with floating point noise if we have two theoretically equal numbers. (floating point noise is not always deterministic, not always strictly reproducible) -> try to add buffer multiply by (1 + 1e-15) or similar to the strict inequality check. (randomized pvalue would have better size, but would not be welcome by statisticians, and we wouldn't get correctly randomized floating point noise :) |
|
That does it Berger: I get essentially the same, small difference in probability point of maximum general rule: no equality or strict inequality checks with floating points |
|
and the extreme corner, all endog identical Below is what I have right now, |
|
Possible complication:
I'm still missing the method that calculates exact distribution pvalue as a function for a given probability. (It's currently duplicated in two methods.) edit: corners prob = 0 and prob = 1 look fine. I can reuse grid for single probability As mentioned before, we never reject equality of proportions at observations (0,0) or (1,1) which are the only ones as extreme as the observed (0,0) or (1,1) |
|
Taking reject mask out of loop is large speedup (7 times) Replacing mask with evaluating at rejection points yields only a smaller speedup in example 0.25 -> 0.21 seconds (fancy indexing is more costly than broadcasting and will only pay off if rejection region is small enough compared to full sample space) This looks like the best we can do, without exploiting monotonicity and a fast cdf/sf if available. |
|
still not improved: I'm using a 1000 point grid search for maximum pvalue, which sounds overkill in smooth cases with just a few local maxima. |
|
example with spike (in one sided test case) replicates example and Figure 3 in Berger 1996 "More Powerful Tests from Confidence Interval p Values", The American Statistician Vol. 50 No. 4 With two-sided alternative, both pvalues, bb and sup, are around 0.021 (i.e. no spike to drive up sup) |
|
I think this should go in with some cleanup/docstrings even if we haven't settled on an API or a new all-in-one approach. similar PR #2723 with also essentially finished functions, but different API. |
31de6d8 to
3facf93
Compare
|
rebased (no merge conflicts) |
| alternative=alternative) | ||
|
|
||
|
|
||
| def statistic(self, y1, y2, prob_var=None, alternative='2-sided'): |
| Currently the p-value when (p1, p2) is either (0, 0) or (1, 1) is one, i.e. | ||
| it is never in the rejection region. This implies that the pvalue is | ||
| always conservative if the both true probabilities approach zero or one. | ||
|
|
There was a problem hiding this comment.
no References in docstrings
|
API maybe there should be a helper function with returns are numbers and tuples not results instances, everything is in a class, so it might be possible to extend to add conf_int later. class name: Also this is in a private module and needs to be added to a public module |
3facf93 to
fecdd8d
Compare
|
rebased, no merge conflicts |
| pval_asymp = pt.pvalue_base | ||
| assert_allclose(pval_asymp, pval_lj_asymp, rtol=0, atol=5e-5) | ||
| pval_mle = pt.pvalue_exactdist_mle() | ||
| #assert_allclose(pval_mle, pval_lj_mle, rtol=0, atol=5e-5) |
There was a problem hiding this comment.
why is this commented out?
Ling Yang don't have the mle version?
|
bump for 0.10 Maybe a general entry-point function like Need also more of the other tests equivalent to confidence interval methods for #2605 |
| if alternative == '2-sided': | ||
| pvalue = stats.chi2.sf(stat, 1) | ||
| else: | ||
| pvalue = stats.norm.sf(stat) |
There was a problem hiding this comment.
this needs to distinguish larger or smaller
|
PR/docstrings are missing references, e.g. Berger web site and what is Ling Yang? Is it easy to extend to non-zero "value"? |
| prob2 = stats.binom.pmf(np.arange(n2 + 1), n1, self.prob_pooled) | ||
|
|
||
| prob = prob1[None, :] * prob2[:, None] | ||
| pvemp = prob[pv < pvo].sum() |
There was a problem hiding this comment.
why does this use strict inequality?
|
This only allows for equality null hypothesis, H0: prop1 = prop2 I'm not sure about using a class based implementation. In poisson, I only used functions. (In my recent round of stats for poisson rates, I didn't look at exact methods for 2indep.) for nonzero null. try to target exact methods for proportion and rates for 2indep for 0.15 |
see #2607
This PR implements an unconditional exact test for the equality of two independent proportions, either based on full max or on Berger/Boos confidence interval test.
verified and unit tested with published example and website with online calculation at print precision.
work in progress, PR so I don't forget this and can go back to other things.
main Todos
I didn't see any spikes yet that are described in several references.
extend: