## Methods in Biostatistics 2 (140.652)

### Multiple comparisons

For this part, you need to install the 'qvalue' package from Bioconductor. Uncomment the first two lines for the installation. Note this can take a wee bit.

```{r}
# source("http://bioconductor.org/biocLite.R")
# biocLite("qvalue")
library(qvalue)
```

#### Null results

```{r}
set.seed(1)
p <- runif(1e5)
hist(p,breaks=101,col="lightgrey",prob=T)
abline(h=1,lwd=2,col="red")
```

#### Example 1: enrichment for low p-values

```{r}
p <- c(runif(1e5),rbeta(1e3,1,1.5)/10)
hist(p,breaks=101,col="lightgrey",prob=T)
abline(h=1,lwd=2,col="red")

# Bonferroni
0.05/length(p)
min(p)

# q-values
q <- qvalue(p)
wh <- order(q$pvalues)
cbind(q$pvalues,q$qvalues)[wh,][1:20,]
```

#### Example 2: enrichment for low p-values

```{r}
p <- c(runif(1e5),runif(10,0,1e-6))
hist(p,breaks=101,col="lightgrey",prob=T)
abline(h=1,lwd=2,col="red")

0.05/length(p)
min(p)

q <- qvalue(p)
wh <- order(q$pvalues)
cbind(q$pvalues,q$qvalues)[wh,][1:20,]
```

Also, check out the function p.adjust() !

### End of code

