# ANCOM-BC formula and ref-levels for interactions

**URL:** https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556
**Category:** User Support
**Created:** [December 8, 2023, 6:51pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556 "2023-12-08T18:51:16Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![kindergarten](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/b38774/32.png) [@kindergarten](https://forum.qiime2.org/u/kindergarten)
#### Post date: [December 8, 2023, 6:51pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/1 "2023-12-08T18:51:16Z")

</div>

Hi

I am trying to perform differential abundance using qiime2-2023.5 and composition ancombc

My metadata is something like this  
Phenotype, Bodysite  
A, L  
A, M  
B, L  
B, M  
C, L  
C, M  
I want to compare A,L vs A,M; B,L vs B,M. I used following parameters

```
--p-formula 'Phenotype + Bodysite' \
--p-reference-levels Phenotype::A Bodysite::L \

```

Output looked like this  
Intercept PhenotypeB PhenotypeC BodysiteM  
I believe PhenotypeB is PhenotypeB (bodysite L+M). Am I correct?

How do I get the desired outcome? e.g. PhenotypeA at bodysiteL vs PhenotypeA at bodysiteM.

Thanks

---

<div class="post-metadata">

### Author: ![colinbrislawn](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinbrislawn/32/6221_2.png) [@colinbrislawn](https://forum.qiime2.org/u/colinbrislawn)
#### Post date: [December 8, 2023, 7:00pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/2 "2023-12-08T19:00:40Z")

</div>

One option is to make a new metadata column:

Phenotype, Bodysite, Combined  
A, L, AatBodysiteL  
A, M, AatBodysiteM  
B, L, BatBodysiteL

Then `--p-formula 'Combined'`

* * *

There may be a better way using a powerful R formula, but I'm not sure what ANCOM-BC supports. Let's see what others suggest!

---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [December 8, 2023, 7:36pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/3 "2023-12-08T19:36:20Z")

</div>



---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [December 8, 2023, 8:30pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/4 "2023-12-08T20:30:14Z")

</div>

Hey @kindergarten,

I think there are a couple of ways to approach this, depending on some details of the exact comparisons you're trying to make!

Within ANCOM-BC, all possible group comparisons will be made (based on the chosen formula), and they will be displayed in reference to a particular intercept for each column used within the formula. So, to provide a simple example - if we had the following column/groups:

**bodysite**  
_gut_  
_tongue_  
_left palm_  
_right palm_

Let's say we'd like to examine the differences between each group in this column, and we'd like to look at those differences in reference to the 'tongue' group. We'd run ancombc with the `--p-formula` parameter set to 'bodysite' and `--p-reference-levels` set to 'bodysite::tongue'. This will provide us with those comparisons, all with respect to 'bodysite:tongue' (i.e. log-fold change for 'bodysitegut', 'bodysiteleft palm', and 'bodysiteright palm').

So what I'm seeing in the metadata columns you've provided is:

- Three groups in the 'Phenotype' column (A, B, C)
- Two groups in the 'Bodysite' column (L, M)

From what you've described, it sounds like you'd like to examine the interaction between Phenotype at each Bodysite group, is that correct? Assuming that's the case, you do have several options that you can provide within the formula column (all of which do require some understanding of linear regression models). You'll want to make sure you have an understanding on whether or not these are dependent/independent variables, and if you'd like to examine the _effect_ of one vs the other and/or the _interaction_ of one vs the other.

[This is a helpful course lecture](https://www.medicine.mcgill.ca/epidemiology/joseph/courses/EPIB-621/interaction.pdf) on interaction terms in linear regression models, which you may find helpful if these are new concepts. Cheers 🦎

---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [December 8, 2023, 8:30pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/5 "2023-12-08T20:30:21Z")

</div>



---

<div class="post-metadata">

### Author: ![kindergarten](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/b38774/32.png) [@kindergarten](https://forum.qiime2.org/u/kindergarten)
#### Post date: [December 9, 2023, 8:16pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/6 "2023-12-09T20:16:45Z")

</div>

hi @lizgehret

Thanks for the detailed explanation.

So what I'm seeing in the metadata columns you've provided is:

```
Three groups in the 'Phenotype' column (A, B, C)
Two groups in the 'Bodysite' column (L, M)

```

Above is correct.

> From what you've described, it sounds like you'd like to examine the interaction between Phenotype at each Bodysite group, is that correct?

I want to compare

1. Phenotype A at bodysite L versus Phenotype A at bodysite M
2. Phenotype B at bodysite L versus Phenotype B at bodysite M
3. Phenotype C at bodysite L versus Phenotype C at bodysite M
4. Phenotype A vs B vs C at bodysite L
5. Phenotype A vs B vs C at bodysite M

To be honest, I read the lecture in provided link twice. I could not understand the math. If it is critical, I would have to learn it.

---

<div class="post-metadata">

### Author: ![colinvwood](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinvwood/32/17303_2.png) [@colinvwood](https://forum.qiime2.org/u/colinvwood)
#### Post date: [December 11, 2023, 5:38pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/7 "2023-12-11T17:38:56Z")

</div>



---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [December 14, 2023, 5:23pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/8 "2023-12-14T17:23:16Z")

</div>

Hi @kindergarten,

Thanks for your patience here! I've gotten tied up with some other things this week but will follow up with you as soon as I am able.

Cheers 🦎

---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [December 14, 2023, 9:44pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/9 "2023-12-14T21:44:34Z")

</div>

Hi @kindergarten,

Thanks for your patience! Happy to go through the comparisons you mentioned below:

```auto
Phenotype A at bodysite L versus Phenotype A at bodysite M
Phenotype B at bodysite L versus Phenotype B at bodysite M
Phenotype C at bodysite L versus Phenotype C at bodysite M

```

The best way to do each of these comparisons will be to filter down your feature table three different times - each time, filtering on the Phenotype you'd like to compare between each bodysite. This would look something like:

```auto
qiime feature-table filter-samples \
--i-table your_feature_table.qza \
--p-where "[Phenotype]='A'" \
--o-filtered-table your_filtered_table_A.qza

```

This would be the same for each phenotype - you would just modify the `where` parameter to be phenotype=B & C to create the other two filtered tables.

From here you can run ANCOM-BC on each of these filtered tables, using `bodysite` in the `formula` parameter. The only thing to be aware of is that one group within your bodysite groups will be selected as the reference (i.e. the differential abundance will be calculated with respect to a particular group). By default, the selected reference level will be chosen in alphabetical order, but you can specify another group if you prefer. So for your data, bodysite L would be the default reference level selected, but you could choose bodysite M if you prefer.

> Phenotype A vs B vs C at bodysite L  
> Phenotype A vs B vs C at bodysite M

These comparisons would be made through a 'global test', which is a parameter not currently exposed in QIIME 2's implementation of ANCOM-BC. If you're interested in utilizing this parameter and are familiar with R, you could run the R implementation of ANCOM-BC (which is what our implementation wraps, just without some of the same functionality). Information on that R package can be found here, if you're interested:

[https://github.com/FrederickHuangLin/ANCOMBC](https://github.com/FrederickHuangLin/ANCOMBC)

Hope this helps! Cheers 🦎

---

<div class="post-metadata">

### Author: ![lizgehret](https://forum.qiime2.org/user_avatar/forum.qiime2.org/lizgehret/32/17128_2.png) [@lizgehret](https://forum.qiime2.org/u/lizgehret)
#### Post date: [December 14, 2023, 9:44pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/10 "2023-12-14T21:44:39Z")

</div>



---

<div class="post-metadata">

### Author: ![kindergarten](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/b38774/32.png) [@kindergarten](https://forum.qiime2.org/u/kindergarten)
#### Post date: [January 2, 2024, 6:50pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/12 "2024-01-02T18:50:45Z")

</div>

Hi @lizgehret  
Happy new year.  
I really appreciate your detailed response to my issue.

For comparing body-sites for a given phenotype:  
I will generate three sub-tables, one for each phenotype.  
I think I can run this analysis in qiime2?  
How do I address taxa levels? Shall I collapse sub-tables to Level 2, 5, 6, 7 and then analyze with qiime2?

For comparing phenotype at a body-site:  
Analysis should be run in R using existing table. Correct?

Thanks  
Gurjit

---

<div class="post-metadata">

### Author: ![cherman2](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cherman2/32/17129_2.png) [@cherman2](https://forum.qiime2.org/u/cherman2)
#### Post date: [January 3, 2024, 4:59pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/13 "2024-01-03T16:59:40Z")

</div>



---

<div class="post-metadata">

### Author: ![timanix](https://forum.qiime2.org/user_avatar/forum.qiime2.org/timanix/32/17879_2.png) [@timanix](https://forum.qiime2.org/u/timanix)
#### Post date: [January 3, 2024, 5:41pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/14 "2024-01-03T17:41:12Z")

</div>

Hello!  
Just in case if @lizgehret on a vacation I will jump in and try my best to address the question.

First of all, happy New Year!

> [@kindergarten](#):
>
> For comparing body-sites for a given phenotype:  
> I will generate three sub-tables, one for each phenotype.  
> I think I can run this analysis in qiime2?

As I understood, you have two sample types, that should be compared versus each other. In that case yes, you can run it separately for each phenotype within Qiime2.

> [@kindergarten](#):
>
> How do I address taxa levels? Shall I collapse sub-tables to Level 2, 5, 6, 7 and then analyze with qiime2?

You can run it at ASV level or at any taxonomy level of your choice. In that case you need to collapse the table to desired level before Ancombc.

> [@kindergarten](#):
>
> For comparing phenotype at a body-site:  
> Analysis should be run in R using existing table. Correct?

If your goal to perform A vs B vs C comparisons then you should follow @lizgehret advice from the earlier comments and run it in R. If you have one phenotype that can be chosen as a reference for two others, then you can run it in Qiime2.

Hope it helps.  
Best,

---

<div class="post-metadata">

### Author: ![cherman2](https://forum.qiime2.org/user_avatar/forum.qiime2.org/cherman2/32/17129_2.png) [@cherman2](https://forum.qiime2.org/u/cherman2)
#### Post date: [January 3, 2024, 5:43pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/15 "2024-01-03T17:43:19Z")

</div>



---

<div class="post-metadata">

### Author: ![kindergarten](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/k/b38774/32.png) [@kindergarten](https://forum.qiime2.org/u/kindergarten)
#### Post date: [January 3, 2024, 6:14pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/16 "2024-01-03T18:14:08Z")

</div>

Hi @timanix  
Thanks for prompt response.

I will collapse phenotype tables to appropriate levels and analyze with qiime2.

For the second part, comparing A vs B vs C, I can assign a reference phenotype in "--p-reference-levels".  
How do I specify the body-site? (I want to compare A vs B vs C at body-site M and so on).  
As per my understanding, I should use --p-formula 'bodysite \* animal'. Is this correct?  
Or shall I filter the table to generate sub-tables for each body site?

Thanks  
Gurjit

---

<div class="post-metadata">

### Author: ![timanix](https://forum.qiime2.org/user_avatar/forum.qiime2.org/timanix/32/17879_2.png) [@timanix](https://forum.qiime2.org/u/timanix)
#### Post date: [January 3, 2024, 6:21pm UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/17 "2024-01-03T18:21:54Z")

</div>

Since from my experience (not a rule!) body-sites have different microbiome profiles I would separate tables based on sample type as well and then compare phenotypes either all vs all in R or vs a reference in Qiime2.

---

<div class="post-metadata">

### Author: ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)
#### Post date: [February 4, 2024, 12:22am UTC](https://forum.qiime2.org/t/ancom-bc-formula-and-ref-levels-for-interactions/28556/18 "2024-02-04T00:22:03Z")

</div>

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
