Skip to content

Commit

Permalink
Fix upper limit of Bonferroni adjusted p-values to 1.0
Browse files Browse the repository at this point in the history
In some cases Bonferroni adjustment might lead to p-values higher than 1.0. For R implementation, see: https://github.com/SurajGupta/r-source/blob/master/src/library/stats/R/p.adjust.R#L40
  • Loading branch information
gokceneraslan authored Jan 4, 2019
1 parent 63d1eb6 commit aaba02f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scanpy/tools/rank_genes_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def rank_genes_groups(
pvals[np.isnan(pvals)] = 1 # set Nan values to 1 to properly convert using Benhjamini Hochberg
_, pvals_adj, _, _ = multipletests(pvals, alpha=0.05, method='fdr_bh')
elif corr_method == 'bonferroni':
pvals_adj = pvals * n_genes
pvals_adj = np.minimum(pvals * n_genes, 1.0)

scores_sort = np.abs(scores) if rankby_abs else scores
partition = np.argpartition(scores_sort, -n_genes_user)[-n_genes_user:]
Expand Down Expand Up @@ -302,7 +302,7 @@ def rank_genes_groups(
pvals[np.isnan(pvals)] = 1 # set Nan values to 1 to properly convert using Benhjamini Hochberg
_, pvals_adj, _, _ = multipletests(pvals, alpha=0.05, method='fdr_bh')
elif corr_method == 'bonferroni':
pvals_adj = pvals * n_genes
pvals_adj = np.minimum(pvals * n_genes, 1.0)

mean_rest[mean_rest == 0] = 1e-9 # set 0s to small value
foldchanges = (means[imask] + 1e-9) / mean_rest
Expand Down Expand Up @@ -358,7 +358,7 @@ def rank_genes_groups(
pvals[np.isnan(pvals)] = 1 # set Nan values to 1 to properly convert using Benhjamini Hochberg
_, pvals_adj, _, _ = multipletests(pvals, alpha=0.05, method='fdr_bh')
elif corr_method == 'bonferroni':
pvals_adj = pvals * n_genes
pvals_adj = np.minimum(pvals * n_genes, 1.0)

mean_rest[mean_rest == 0] = 1e-9 # set 0s to small value
foldchanges = (means[imask] + 1e-9) / mean_rest
Expand Down

0 comments on commit aaba02f

Please sign in to comment.