IHW 1.33.0

You will probably be familiar with multiple testing procedures that take a set of p-values and then calculate adjusted p-values. Given a significance level \(\alpha\), one can then declare the rejected hypotheses. In R this is most commonly done with the `p.adjust`

function in the *stats* package, and a popular choice is controlling the false discovery rate (FDR) with the method of (Benjamini and Hochberg 1995), provided by the choice `method="BH"`

in `p.adjust`

. A characteristic feature of this and other methods â€“responsible both for their versatility and limitationsâ€“ is that they do not use anything else beyond the p-values: no other potential information that might set the tests apart, such as different signal quality, power, prior probability.

IHW (Independent Hypothesis Weighting) is also a multiple testing procedure, but in addition to the p-values it allows you to specify a covariate for each test. The covariate should be informative of the power or prior probability of each individual test, but is chosen such that the p-values for those hypotheses that are truly null do not depend on the covariate (Ignatiadis et al. 2016). Therefore the input of IHW is the following:

- a vector of p-values (of length \(m\)),
- a matching vector of covariates,
- the significance level \(\alpha \in (0,1)\) at which the FDR should be controlled.

IHW then calculates weights for each p-value (non-negative numbers \(w_i \geq 0\) such that they average to 1, \(\sum_{i=1}^m w_i = m\)). IHW also returns a vector of adjusted p-values by applying the procedure of Benjamini Hochberg (BH) to the weighted p-values \(P^\text{weighted}_i = \frac{P_i}{w_i}\).

The weights allow different prioritization of the individual hypotheses, based on their covariate. This means that the ranking of hypotheses with p-value weighting is in general different than without. Two hypotheses with the same p-value can have different weighted p-values: the one with the higher weight will then have a smaller value of \(P^\text{weighted}_i\), and consequently it can even happen that one but not the other gets rejected by the subsequent BH procedure.

As an example, letâ€™s see how to use the IHW package in analysing for RNA-Seq differential gene expression. and then also look at some other examples where the method is applicable.

We analyze the *airway* RNA-Seq dataset using *DESeq2* (Love, Huber, and Anders 2014).

```
library("DESeq2")
library("dplyr")
data("airway", package = "airway")
dds <- DESeqDataSet(se = airway, design = ~ cell + dex) %>% DESeq
deRes <- as.data.frame(results(dds))
```

The output is a dataframe with the following columns, and one row for each tested hypothesis (i.e., for each gene):

`colnames(deRes)`

```
## [1] "baseMean" "log2FoldChange" "lfcSE" "stat"
## [5] "pvalue" "padj"
```

In particular, we have p-values and baseMean (i.e., the mean of normalized counts) for each gene. As argued in the *DESeq2* paper, these two statistics are approximately independent under the null hypothesis. Thus we have all the ingredient necessary for a *IHW* analysis (p-values and covariates), which we will apply at a significance level 0.1.

First load IHW:

```
library("IHW")
ihwRes <- ihw(pvalue ~ baseMean, data = deRes, alpha = 0.1)
```

This returns an object of the class ihwResult. We can get, e.g., the total number of rejections.

`rejections(ihwRes)`

`## [1] 4892`

And we can also extract the adjusted p-values:

`head(adj_pvalues(ihwRes))`

`## [1] 0.00102074 NA 0.16260848 0.86124686 1.00000000 1.00000000`

`sum(adj_pvalues(ihwRes) <= 0.1, na.rm = TRUE) == rejections(ihwRes)`

`## [1] TRUE`

We can compare this to the result of applying the method of Benjamini and Hochberg to the p-values only:

```
padjBH <- p.adjust(deRes$pvalue, method = "BH")
sum(padjBH <= 0.1, na.rm = TRUE)
```

`## [1] 4099`

*IHW* produced quite a bit more rejections than that.
How did we get this power? Essentially it was possible by assigning appropriate weights to each hypothesis. We can retrieve the weights as follows:

`head(weights(ihwRes))`

`## [1] 2.366789 NA 2.366789 2.366789 1.263387 0.000000`

Internally, what happened was the following: We split the hypotheses into \(n\) different strata (here \(n=22\)) based on increasing value of `baseMean`

and we also randomly split them into \(k\) folds (here \(k=5\)). Then, for each combination of fold and stratum, we learned the weights. The discretization into strata facilitates the estimation of the distribution function conditionally on the covariate and the optimization of the weights. The division into random folds helps us to avoid overfitting the data, something which could otherwise result in loss of control of the FDR (Ignatiadis et al. 2016).

The values of \(n\) and \(k\) can be accessed through

`c(nbins(ihwRes), nfolds(ihwRes))`

`## [1] 22 5`

In particular, each hypothesis test gets assigned a weight depending on the combination of its assigned fold and stratum.

We can also see this internal representation of the weights as a (\(n\) X \(k\)) matrix:

`weights(ihwRes, levels_only = TRUE)`

```
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [2,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [3,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [4,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [5,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [6,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [7,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [8,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [9,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [10,] 0.0000000 0.0000000 0.00000000 0.0000000 0.0000000
## [11,] 0.2109405 0.2081831 0.03842498 0.2571217 0.2597236
## [12,] 0.9162309 0.7947122 0.21091412 0.8534397 0.8345059
## [13,] 0.9254299 0.7947122 0.92276703 0.8534397 0.9075388
## [14,] 1.2633867 1.0511555 1.25975138 1.2265498 1.2389620
## [15,] 2.8869427 2.4482091 2.52720882 2.8097858 2.3857529
## [16,] 2.8869427 2.4482091 2.52720882 2.8097858 2.3857529
## [17,] 2.0875843 2.3667885 3.19833627 2.8097858 2.3503772
## [18,] 2.3930928 2.3667885 2.88745672 2.3268306 2.3503772
## [19,] 2.1950851 2.3667885 2.38786536 1.9327308 2.2688409
## [20,] 2.4675513 2.4159384 2.38786536 2.3956042 2.3637281
## [21,] 1.8521421 2.2447180 1.58228861 1.5405863 2.3335436
## [22,] 2.2744492 2.2447180 2.26790467 2.0358541 2.2112801
```

`plot(ihwRes)`

We see that the general trend is driven by the covariate (stratum) and is the same across the different folds. As expected, the weight functions calculated on different random subsets of the data behave similarly. For the data at hand, genes with very low `baseMean`

count get assigned a weight of 0, while genes with high baseMean count get prioritized.

`plot(ihwRes, what = "decisionboundary") `