-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Avoid cancellations in nanskew/nankurt. #12121
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
7335213
to
92bf9a4
Compare
@@ -888,6 +888,103 @@ def prng(self): | |||
return np.random.RandomState(1234) | |||
|
|||
|
|||
class TestNanskewFixedValues(tm.TestCase): | |||
|
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.
add the issue number here as a comment
very minor change. pls rebase. ping when ready. |
|
||
result = ((np.sqrt(count * count - count) * C) / | ||
((count - typ(2)) * np.sqrt(B)**typ(3))) | ||
result = count * (count-1) ** 0.5 / (count-2) * m3 / m2 ** 1.5 |
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.
maybe add parens for clarity of precedence?
In computing skewness, is the computation of |
92bf9a4
to
7b310da
Compare
@jreback Thanks for the quick review. I made the changes, and Travis passes. @kawochen Not sure why you refer to |
@jvkersch I referred to |
@jvkersch thanks! |
@kawochen I see, that makes sense; I didn't think about the alternate signs. Thanks for the clarification. |
closes #11974
This replaces the implementation of
nanskew
andnankurt
by an algorithm that does not produce round-off error due to subtracting very similar large values. The sample skew and kurtosis are computed directly from the moments, rather than expanding the moments, which leads to cancellation errors. The algorithm implemented here is about as efficient as the original implementation (in terms of time and memory); a more efficient one-pass algorithm is certainly possible but would require some Cython code.