Created
April 3, 2019 22:32
-
-
Save egafni/2c8d7780aeccb4fbd014871096975287 to your computer and use it in GitHub Desktop.
poisson outliers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def poisson_outliers(arr, min_pval=.01, min_size_to_filter=5): | |
""" | |
>>> poisson_outliers([1,1,1,1,1,2,3]) | |
array([False, False, False, False, False, False, False], dtype=bool) | |
>>> poisson_outliers([1,1,1,1,1,2,10]) | |
array([False, False, False, False, False, False, True], dtype=bool) | |
>>> poisson_outliers([1,1,10]) | |
array([False, False, False], dtype=bool) | |
""" | |
arr = np.asarray(arr) | |
mu = np.median(arr) | |
pvals = poisson(mu).sf(arr) | |
# outliers have pvalues that are too unlikely given our sample size | |
if len(arr) >= min_size_to_filter: | |
is_outlier = pvals < min(1.0 / len(arr), min_pval) | |
else: | |
is_outlier = np.zeros_like(pvals).astype(bool) | |
return is_outlier |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment