library(ggplot2)
if (require("qvalue")) {
set.seed(2014)
# generate p-values from many one sample t-tests: half of them null
oracle <- rep(c(0, .5), each=1000)
pvals <- sapply(oracle, function(mu) t.test(rnorm(15, mu))$p.value)
qplot(pvals)
q <- qvalue(pvals)
tidy(q)
head(augment(q))
glance(q)
# use augmented data to compare p-values to q-values
ggplot(augment(q), aes(p.value, q.value)) + geom_point()
# use tidy see how pi0 estimate changes with lambda, comparing
# to smoothed version
g <- ggplot(tidy(q), aes(lambda, pi0, color=smoothed)) + geom_line()
g
# show the chosen value
g + geom_hline(yintercept=q$pi0, lty=2)
}
Run the code above in your browser using DataLab