# Multiple variables used as the references

**URL:** <https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854>\
**Category:** MaAsLin\
**Created:** [November 30, 2021, 1:52pm UTC](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854 "2021-11-30T13:52:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayuhhh](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/ayuhhh/32/993_2.png) [@ayuhhh](https://forum.biobakery.org/u/ayuhhh)\
**Post date:** [November 30, 2021, 1:52pm UTC](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854/1 "2021-11-30T13:52:53Z")

</div>

Hi,

I am running an analysis with one predictor of interest and several categorical covariates. As the tutorial said, for the reference parameter, “semi-colon delimited for multiple variables”.

My current code goes like this:  
Maaslin2(input\_data, input\_metadata,‘demo\_output’, transform = “AST”,  
max\_significance = 0.1,  
fixed\_effects = c(“sex”,“age\_group”,“BMI\_g”,“smoking”,  
“alcohol”,“MET\_g”,“red\_meat”),  
normalization = ‘NONE’,  
reference = c(“age\_group,50plus”,“BMI\_g,24minus”,“smoking,non-smoker”,  
“alcohol,no”,“MET\_g,A”,“red\_meat,1pw\_minus”))

but it doesn’t work well for the covariates. So I wonder how to set the reference parameter for multiple variables.

Thank you!  
Yuhan

---

<div class="post-metadata">

**Author:** ![nickp60](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/nickp60/32/1031_2.png) [@nickp60](https://forum.biobakery.org/u/nickp60)\
**Post date:** [December 4, 2021, 10:08pm UTC](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854/2 "2021-12-04T22:08:14Z")

</div>

HI Yuhan,  
try doing the following for your references, rather than having them as a vector.

```auto
reference = “age_group,50plus;BMI_g,24minus;smoking,non-smoker;alcohol,no;MET_g,A;red_meat,1pw_minus”

```

---

<div class="post-metadata">

**Author:** ![Kelsey\_Thompson](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/kelsey_thompson/32/65_2.png) [@Kelsey\_Thompson](https://forum.biobakery.org/u/Kelsey_Thompson)\
**Post date:** [December 6, 2021, 1:07pm UTC](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854/3 "2021-12-06T13:07:14Z")

</div>

Hi @ayuhhh,

Apologies for not being clearer in the tutorial! We should add an example where we set multiple references for different variables - I will add that to our improvements list.

I haven’t tried @nickp60 method, thank you for offering that one! Adding more parentheses should also work (e.g. -

```auto
reference = c((“age_group,50plus”),(“BMI_g,24minus”),(“smoking,non-smoker”),
(“alcohol,no”),(“MET_g,A”),(“red_meat,1pw_minus”)))

```

I hope this helps!  
Best,  
Kelsey

---

<div class="post-metadata">

**Author:** ![Jennifer\_Berkowitz](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/jennifer_berkowitz/32/1392_2.png) [@Jennifer\_Berkowitz](https://forum.biobakery.org/u/Jennifer_Berkowitz)\
**Post date:** [April 17, 2022, 10:53pm UTC](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854/4 "2022-04-17T22:53:03Z")

</div>

Hi Kelsey,

I tried doing that and keep getting the same error. What am I missing? Here’s my code:

metadat.sub$Treatmentmod= factor(metadat.sub$Treatment,  
levels = c(“Bare”, “Mustard”, “Radish”))

fit\_data = Maaslin2(  
input\_data = otus.r,  
input\_metadata = metadat.sub,  
output = “16S\_output.trt”,  
fixed\_effects = c(“Treatmentmod”),  
reference = c(“Bare”,“Mustard”,“Radish”))

It keeps returning this error:

Error in Maaslin2(input\_data = otus.r, input\_metadata = metadat.sub, output = “16S\_output.trt”, :  
Please provide the reference for the variable ‘Treatmentmod’ which includes more than 2 levels: Bare, Radish, Mustard.

---

<div class="post-metadata">

**Author:** ![Jennifer\_Berkowitz](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/jennifer_berkowitz/32/1392_2.png) [@Jennifer\_Berkowitz](https://forum.biobakery.org/u/Jennifer_Berkowitz)\
**Post date:** [April 17, 2022, 11:01pm UTC](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854/5 "2022-04-17T23:01:58Z")

</div>

Wait! I got it, here’s the code that worked for me, for reference.

metadat.sub$Treatmentmod= factor(metadat.sub$Treatment,  
levels = c(“Bare”, “Mustard”, “Radish”))  
fit\_data = Maaslin2(  
input\_data = otus.r,  
input\_metadata = metadat.sub,  
output = “16S\_output.trt”,  
fixed\_effects = c(“Treatmentmod”),  
reference = c(“Treatmentmod,Bare”))

---

<div class="post-metadata">

**Author:** ![Kelsey\_Thompson](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/kelsey_thompson/32/65_2.png) [@Kelsey\_Thompson](https://forum.biobakery.org/u/Kelsey_Thompson)\
**Post date:** [April 19, 2022, 12:30pm UTC](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854/6 "2022-04-19T12:30:46Z")

</div>

Hi @Jennifer_Berkowitz,

Yup, that is exactly what is needed here. I’m glad you could find the answer! Let us know if you have any additional questions.

Best,  
Kelsey
