Skip to content

Commit 4f8ae43

Browse files
committed
added PValueHistogram() (not used yet)
1 parent cadf823 commit 4f8ae43

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

‎seance_5/R/pvalue_histogram.R‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#' @title draw a P-value histogram and return estimations of proportions of cases respectively under H0 and H1.
2+
#' @author Jacques van Helden
3+
#' @param Pvalues a vector of P-values.
4+
#' Must include all the p-values computed during a multiple testing,
5+
#' and can by no way be restricted to a selection of the significant ones.
6+
#' @param main="Distribution of P-values" main title for the histogram
7+
#' @param alpha=NULL if speficied, indicate the number of genes passing this p-value threshold
8+
#' @param bins=20 number of class intervals in the histogram
9+
#' @param ... other parameters are passed to hist()
10+
#' @export
11+
PvalueHistogram <- function(Pvalues,
12+
main = "Distribution of P-values",
13+
alpha = NULL,
14+
lambda = 0.5,
15+
bins = 20,
16+
...) {
17+
breaks <- seq(from = 0, to = 1, by = 1/bins)
18+
hist(Pvalues, breaks = breaks, col = "grey",
19+
main = main,
20+
xlab = "nominal P-value",
21+
ylab = "Number of genes",
22+
...)
23+
24+
## Estimate the proportion of genes under H0 / H1 following the method from Storey-Tibshirani (2003)
25+
pval.stat <- list()
26+
pval.stat$N <- length(Pvalues)
27+
pval.stat$m0 <- sum(Pvalues >= parameters$lambda) / parameters$lambda
28+
pval.stat$m1 <- pval.stat$N - pval.stat$m0
29+
pval.stat$pi0 <- pval.stat$m0 / pval.stat$N
30+
pval.stat$pi1 <- 1 - pval.stat$pi0
31+
# t(as.data.frame(pval.stat))
32+
33+
34+
## Display the indicators
35+
legend.text <- c(
36+
paste("N = ", prettyNum(big.mark = ",", pval.stat$N)),
37+
paste("m0 = ", prettyNum(big.mark = ",", pval.stat$m0)),
38+
paste("m1 = ", prettyNum(big.mark = ",", pval.stat$m1)),
39+
paste("pi0 = ", signif(digits = 2, pval.stat$pi0)),
40+
paste("pi1 = ", signif(digits = 2, pval.stat$pi1))
41+
)
42+
if (!is.null(alpha)) {
43+
pval.stat$alpha <- alpha
44+
pval.stat$positives <- sum(Pvalues < alpha)
45+
legend.text <- append(
46+
legend.text,
47+
c(paste("alpha = ", signif(digits = 2, pval.stat$alpha)),
48+
paste("positives = ", pval.stat$positives)))
49+
}
50+
51+
legend("topright", legend = legend.text)
52+
53+
## Draw horizontal line to denote cases under H1
54+
abline(h = pval.stat$m0 / bins, col="blue")
55+
56+
## Return stats
57+
return(pval.stat)
58+
}

0 commit comments

Comments
 (0)