-
Notifications
You must be signed in to change notification settings - Fork 60
pseudo-p significance calculation #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #281 +/- ##
=====================================
Coverage 82.0% 82.0%
=====================================
Files 24 25 +1
Lines 3489 3538 +49
=====================================
+ Hits 2861 2902 +41
- Misses 628 636 +8
🚀 New features to boost your workflow:
|
|
OK, done here on the logic & implementation. Thank you @JosiahParry for getting the ball rolling here 😄 Very much appreciated! I've re-implemented the percentile-based two-sided test from scratch using I don't think we should expose the The percentile will always equal the folded version for symmetric distributions, but the folded version becomes a directed test as skew increases. I think that the (over+under)/all is also the intended estimand of the If other maintainers approve these four options ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet. presume the stuff in main gets moved to a test file or something but this is great
If other maintainers approve these four options (greater, lesser, two-sided, and directed) for the user classes and a folded option for this function only (for replication/testing purposes) I can start propagating this across the user classes.
+1
esda/significance.py
Outdated
| percentile = (reference_distribution < test_stat).mean(axis=1) | ||
| bounds = np.column_stack((1 - percentile, percentile)) * 100 | ||
| bounds.sort(axis=1) | ||
| lows, highs = np.row_stack( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be able to be vectorised, but I couldn't quickly figure that out. the following did not generate the same results as below:
stats.scoreatpercentile(reference_distribution, bounds, axis=1)|
I am still working on this, but I recall now why the implementation of an "alternative" argument was a bit trickier than I expected... because we allow for the user to "discard" the random replicates, rather than store them, we have to push the significance logic all the way down to the conditional randomization It seems clear to me that
If 1-4 are correct, this means we don't need to change any of the numba code. The correction can be calculated as So, if we implement our current test for local stats without flipping (as greater), generate 1-p_sim (as lesser), and implement the above correction for the two-sided test ( Is that OK w/ other maintainers? |
|
This is too much stats for me to say anything useful. |
Same for me. |
jGaboardi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the topic is over my head, my approval is based on a general review.
|
One further wrinkle as well: some global Moran tests support directed testing a binary option already. Notably, if For us to roll-out the testing across all the classes, we need to consider if this option should be deprecated in favor of an explicit "alternative" option? Right now, there's no way to force a direction on these tests. |
I think this is OK. One thing to check is if:
|
Sure, that is what I initially thought & what @JosiahParry suggested. The reason why I'm thinking it's actually Thinking another way, in the percentile-based version of the test, you compute the percentile the simulation code at the end of |
|
@ljwolf I was looking at the discussions in this PR and the other related issue. The correction for the two-sided test |
|
Thank you for the explanation @ljwolf. I think I'm almost there/onboard! It's worth calling out explicitly this formula can result in a p-value > 1.0 which should also be handled e.g. p_sim = 0.65
nsim = 999
(p_corrected = (2*p_sim - (1/(nsim + 1))))
#> [1] 1.299
if (p_corrected > 1) {
1.0
} else {
p_corrected
}
#> [1] 1Additionally, would you mind elaborating why it is calc_p_sim <- function(p_sim, nsim) {
(p_corrected = (2*p_sim - (1/(nsim + 1))))
if (p_corrected > 1) {
1.0
} else {
p_corrected
}
}
calc_p_sim(0.05, 49)
#> [1] 0.08
calc_p_sim(0.05, 99)
#> [1] 0.09
calc_p_sim(0.05, 999)
#> [1] 0.099 |
esda/significance.py
Outdated
| the directed p-value is half of the two-sided p-value, and corresponds to running the | ||
| lesser and greater tests, then picking the smaller significance value. This is not advised. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this will be untrue if the adjustment is added
|
Hi! back again :) this has not been forgotten---it is the highest priority for me when I have development time. I needed to move to a pure numpy version of the two-sided percentile test in order to push it down into the
We now need to do some profiling, but hopefully there is not much gain from doing it inline vs. calling another jitted function on singly-typed input. |
|
@weikang9009 notes correctly that we will also need to update the notebooks where local/global statistics are used before merging this. |
|
the affected notebook has been fixed and #376 has been addressed! |
|
I think this is ready to merge. |
|
Great work, @ljwolf ! |
|
Thanks! it seems there's a broadcasting issue that's numba-version dependent. I will squash this issue, and then it's ready. |
|
OK, all tests are passing except windows, which look like a build issue. Could we merge this? Or, can I get some help to identify the issue with the windows build? This touches numba code, but no code is specific to windows, and all tests on linux/macos pass. |
|
Thanks @martinfleis! @sjsrey can you merge? |
This PR drafts a function
calculate_significance()to provide a consistent way to calculate pseudo-p values from a reference distribution.It is based on the discussion at #199