FrederickHuangLin / ANCOMBC

Differential abundance (DA) and correlation analyses for microbial absolute abundance data
https://www.nature.com/articles/s41467-020-17041-7
108 stars 29 forks source link

How to setting contrast matrix for testing umbrella shape #204

Closed Axolotl233 closed 1 year ago

Axolotl233 commented 1 year ago

Hi,

Thank you very much for devoloping ANCOMBC2, it is a wonderful package. Although here you have uploaded detailed tutorial in Github and Bioconductor, I still have some question about contrast matrix setting in trend test.

I‘m working on a microbiota dataset with three groups (A, B, C), each group has 30+ samples. Now I want to find some microbiota taxons which have specific pattern in these groups using trend test of ANCOMBC. It is easy for detecting taxon which have monotonic trendency (increasing or decreasing) between these three groups, because it have detailed code in example. but for testing umbrella shape (convex and concave), i didn't find any example for setting contrast matrix.

Here is a code i want to test convex umbrella shape. If B is reference, I need to test B>A and B>C matrix(c(-1, 0, -1, 1),nrow = 2, byrow = TRUE) and setting node = 1 Is it right? Could you kindly give me some advice for testing umbrella shape if this code is not right?

Thanks, Nemo

FrederickHuangLin commented 1 year ago

Hi Nemo,

Thanks for your inquiry.

ANCOM-BC2 pattern analysis is able to identify potential patterns by testing the contrast:

$$Ax \ge 0$$

where $A$ is the contrast matrix and $x$ is the vector of parameters.

For instance, in this example, we want to identify taxa that are monotonically increasing across three groups, A, B, and C. Note that A is the reference group, and the parameters we can estimate are the differences as compared to the reference group, i.e.,

$$x = (\text{B - A}, \text{C - A})^T$$

To test the monotonically increasing trend:

$$H_0: \text{A} = \text{B} = \text{C}$$

$$H_1: \text{A} \le \text{B} \le \text{C} \quad \text{with at least one strict inequality}$$

We are essentially testing:

$$H_0: 0 = \text{B - A} = \text{C - A}$$

$$H_1: 0 \le \text{B - A} \le \text{C - A} \quad \text{with at least one strict inequality}$$

Thus, we shall specify the contrast matrix $A$ as

$$ A = \begin{bmatrix} 1 & 0 \ -1 & 1 \ \end{bmatrix} $$

The first row of $A$ matrix, $(1, 0)$, indicates that $\text{"B - A"} \ge 0$, and the second row, $(-1, 1)$ represents $\text{"C - A"} - \text{"B- A"} \ge 0$.

Similarly, to test for the monotonically decreasing trend:

$$H_0: \text{A} = \text{B} = \text{C}$$

$$H_1: \text{A} \ge \text{B} \ge \text{C} \quad \text{with at least one strict inequality}$$ We shall specify the contrast matrix $A$ as

$$ A = \begin{bmatrix} -1 & 0 \ 1 & -1 \ \end{bmatrix} $$

Lastly, to test for an umbrella trend:

$$H_0: \text{A} = \text{B} = \text{C} $$

$$H_1: \text{A} \le \text{B} \ge \text{C} \quad \text{with at least one strict inequality}$$

We shall specify the contrast matrix $A$ as

$$ A = \begin{bmatrix} 1 & 0 \ 1 & -1 \ \end{bmatrix} $$

For testing monotonic trends (increasing or decreasing), one should specify the node parameter in trend_control as the last position of x. In this example, the vector of parameters $x$ is of length 2, thus, the last position is 2. For testing umbrella shape, such as in the above umbrella shape example, one should set node as the position of the turning point of x. In this example, the turning position is B, thus, node = 1.

Best, Huang

Axolotl233 commented 1 year ago

Hi Huang,

Thank you for your detailed information, now I know how to setting contrast matrix of umbrella shape. You can close this issue now.

Thank you and bests regards, Nemo