# Reference values for a categorical fixed effect variable

**URL:** <https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121>\
**Category:** MaAsLin\
**Created:** [October 7, 2020, 3:28am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121 "2020-10-07T03:28:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [October 7, 2020, 3:28am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/1 "2020-10-07T03:28:09Z")

</div>

Hello,

I am trying to use the maaslin2 package to model the association between a categorical intervention variable (3 levels, character variable) and OTUs. My data is longitudinal with repeated measures so I am using a mixed model with fixed effects for the intervention and random effects for my participant ID.

I’d like to set the reference category for my intervention variable and have tried to install the latest version which has the reference option (as suggested here: [Which factor level to compare with](https://forum.biobakery.org/t/which-factor-level-to-compare-with/1014)) but I am getting an unused argument error when I try to run my code. Example:

fit\_data ← Maaslin2(  
frmeTaxa, frmeMetadata,  
“file”,  
fixed\_effects = c(‘intervention’), random\_effects = c(‘ID’),  
min\_abundance = 0.0001, min\_prevalence = 0.2,  
reference=“int1”)

> Error in Maaslin2(frmeTaxa, frmeMetadata, … :  
> unused argument (reference = Calcium - 2)

Any idea what my issue might be? Is there a way to confirm that I have installed the version of maaslin2 with the reference option?

(The code works nicely without the reference option added.)

Thanks!

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [October 7, 2020, 1:05pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/2 "2020-10-07T13:05:35Z")

</div>

Hi @Lyoon6 - this needs to be provided as a string of `variable,reference` (semi-colon delimited for multiple variables) which in your case translates to `reference = intervention,int1 `.

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 1, 2020, 6:57am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/3 "2020-12-01T06:57:41Z")

</div>

Hi Himel,

Sorry, I am still getting an unused argument error with my reference group.

My code:

fit\_data \<- Maaslin2(  
frmeTaxa, frmeMetadata,  
“file”,  
fixed\_effects = c(‘key’),  
random\_effects = c(‘ID’),  
min\_abundance = 0.0001,  
min\_prevalence = 0.2,  
transform = “NONE”,  
normalization = ‘TMM’,  
analysis\_method=‘ZINB’,  
reference=key,Post-Combined  
)

The variable ‘key’ is a categorical variable with character values (e.g., “Post-Combined”, “Pre-Combined”, etc.). Is this a problem with how I am specifying the name of the category? Or you do think there is something else going on? I’ve also tried putting quotes around the reference as shown under Examples here: [https://bioconductor.org/packages/devel/bioc/manuals/Maaslin2/man/Maaslin2.pdf](https://bioconductor.org/packages/devel/bioc/manuals/Maaslin2/man/Maaslin2.pdf) (e.g., reference=‘key,Post-Combined’)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 1, 2020, 12:56pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/4 "2020-12-01T12:56:48Z")

</div>

Hi @Lyoon6 - if your `key` variable has only 2 levels, this option will not work. Assuming that it has at least three levels, you might want to specify the reference as follows: `reference = c('key,Post-Combined')`. Let me know if that resolves the error.

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 1, 2020, 4:52pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/5 "2020-12-01T16:52:42Z")

</div>

My variable has 6 levels, so it shouldn’t be an issue and unfortunately `c('key,Post-Combined')` also did not work.

I’d like to specify the reference variable so that I can better understand my output. As it stands, when I view the all\_results file, I have trouble understanding the comparisons being made when the output looks like this. Hence my trying to specify a reference group.

| metadata | feature | value | coef | stderr | N | N.not.0 | pval | qval |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| key | OTU1 | Pre-Inulin | 0.16585027 | 0.089133456 | 60 | 60 | 0.068338653 | 0.90003414 |
| key | OTU2 | Pre-Calcium | -0.037791923 | 0.018726267 | 60 | 58 | 0.049543834 | 0.90003414 |
| key | OTU3 | Post-Inulin | 0.045776485 | 0.019071219 | 60 | 60 | 0.020575383 | 0.90003414 |
| key | OTU5 | Post-Combined | -0.024608982 | 0.01110134 | 60 | 58 | 0.031719596 | 0.90003414 |

Do you have any other suggestions on an alternative way to do this?

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 1, 2020, 5:29pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/6 "2020-12-01T17:29:31Z")

</div>

@Lyoon6 I am not sure how you are getting the `all_results ` file if you have a fixed effect with more than 2 levels as you are expected to see something like this:

`Please provide the reference for the variable 'key' which includes more than 2 levels: ...`

Could you please clarify how you got the output file?

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 1, 2020, 6:03pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/7 "2020-12-01T18:03:49Z")

</div>

Hello, sure.  
I have a .tsv file which contains metadata and OTU RA. Samples are rows. The key variable is a 6-level categorical variable with character values. The ID variable is the participant ID. This is a longitudinal study, so there are multiple samples per participant.

When I run my code, files are placed into the “maaslin” folder specified in the code. The files I see are: all\_results.tsv, maaslin2, residuals.rds, significant\_results.tsv, and a figures folder. The code appears to at the very least run (according to the log), though there are no significant associations. I can open the all\_results file to see the table that I posted an excerpt from above.

Here is the full code.

#Read in data file  
frmeData = read.csv( file = “file.tsv”,  
sep = “\t”, header = T, row.names = 1 )

#Break up the data into two data frames (metadata and taxa)  
frmeMetadata = data.frame(frmeData[1:16])  
frmeTaxa = data.frame(t( frmeData[17:ncol( frmeData )] ))

#Run Maaslin2  
fit\_data \<- Maaslin2(  
frmeTaxa, frmeMetadata,  
“C:/Users…/maaslin”,  
fixed\_effects = c(‘key’),  
random\_effects = c(‘ID’),  
min\_abundance = 0.0001,  
min\_prevalence = 0.2,  
transform = “NONE”)

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 1, 2020, 7:08pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/8 "2020-12-01T19:08:08Z")

</div>

OK - that makes sense, which means the code is working without the `reference` option which is weird as it should throw an error for fixed effects with \>2 levels. Does the following return TRUE?

`is.factor(frmeMetadata$key)`

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 1, 2020, 7:29pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/9 "2020-12-01T19:29:50Z")

</div>

No, it reuters FALSE. If I convert the variable to a factor (frmeData$key \<- as\_factor(frmeData$key)), it returns TRUE but still runs into the same unused argument issue.

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 1, 2020, 7:52pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/10 "2020-12-01T19:52:16Z")

</div>

Thanks, @Lyoon6. In order to debug this issue, I need to reproduce the error on my end. Would you be able to share a subset of your de-identified data?

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 1, 2020, 7:55pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/11 "2020-12-01T19:55:48Z")

</div>

Sure, I can do that. Should I send you an email?

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 1, 2020, 8:09pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/12 "2020-12-01T20:09:54Z")

</div>

Sure. Email works or if you are fine with sharing the feature and metadata files here that can work as well.

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 1, 2020, 10:28pm UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/13 "2020-12-01T22:28:54Z")

</div>

Hi @Lyoon6 - thanks for sharing the data. I have run the following which seems to be generating the correct output. Could you please verify if this chunk of code works on your end as well?

```auto
##################
# Load libraries #
##################

library(data.table)
library(tibble)
library(Maaslin2)

################
# Load dataset #
################

df<-data.table::fread('./RA_OTUs_sub.tsv')
frmeDataSub<-column_to_rownames(df, 'V1')
frmeMetadataSub = data.frame(frmeDataSub[1:3])
frmeTaxaSub = data.frame(frmeDataSub[4:ncol(frmeDataSub)])

################
# Run MaAsLin2 #
################

fit_data <- Maaslin2(input_data = frmeTaxaSub, 
                     input_metadata = frmeMetadataSub,
                     output = getwd(),
                     fixed_effects = 'key',
                     random_effects = 'ID',
                     min_abundance = 0.0001,
                     min_prevalence = 0.2,
                     transform = 'NONE',
                     reference = 'key,Post-Te')

```

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 2, 2020, 1:02am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/14 "2020-12-02T01:02:03Z")

</div>

Hi @himel.mallick-

Unfortunately, I’m still getting the same error message:

Error in Maaslin2(input\_data = frmeTaxaSub, input\_metadata = frmeMetadataSub, :  
unused argument (reference = “key,Post-Te”)

I went and uninstalled-reinstalled Maaslin2 and still got the error with the exact code you provided:

library(data.table)  
library(tibble)  
library(Maaslin2)

################

# Load dataset

################

df\<-data.table::fread(“C:/Users/…/RA\_OTUs\_sub.tsv”)  
frmeDataSub\<-column\_to\_rownames(df, ‘V1’)  
frmeMetadataSub = data.frame(frmeDataSub[1:3])  
frmeTaxaSub = data.frame(frmeDataSub[4:nrow(frmeDataSub)])

################

# Run MaAsLin2

################

fit\_data \<- Maaslin2(input\_data = frmeTaxaSub,  
input\_metadata = frmeMetadataSub,  
output = getwd(),  
fixed\_effects = ‘key’,  
random\_effects = ‘ID’,  
min\_abundance = 0.0001,  
min\_prevalence = 0.2,  
transform = ‘NONE’,  
reference = ‘key,Post-Te’)

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 2, 2020, 2:07am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/15 "2020-12-02T02:07:05Z")

</div>

Hi @Lyoon6 - have you tried installing directly from GitHub? Also, after installing and loading, could you please verify if you see the option `reference` in the function arguments when you type `?Maaslin2` in `R`? It looks like your function call is not recognizing the argument which can only happen with an older version.

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 2, 2020, 2:42am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/16 "2020-12-02T02:42:16Z")

</div>

Ah- that’s the problem! No reference option in the function arguments. It must be an older version of Maaslin2.

This is what I was using to download originally:

if(!requireNamespace(“BiocManager”, quietly = TRUE))  
install.packages(“BiocManager”)  
BiocManager::install(“Maaslin2”)

Are there instructions to download from GitHub?

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [December 2, 2020, 3:08am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/17 "2020-12-02T03:08:20Z")

</div>

You can simply do the following:

```auto
library(devtools)
devtools::install_github("biobakery/maaslin2")

```

I am glad we have identified the issue. Re-installing should resolve the issue on your end (let me know if not).

---

<div class="post-metadata">

**Author:** ![Lyoon6](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Lyoon6](https://forum.biobakery.org/u/Lyoon6)\
**Post date:** [December 2, 2020, 4:12am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/18 "2020-12-02T04:12:14Z")

</div>

Reference argument now available & code running.

Thanks for your help working through this. Can’t believe the solution was as simple as updating the version.

---

<div class="post-metadata">

**Author:** ![Dhrati\_Patangia](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/dhrati_patangia/32/786_2.png) [@Dhrati\_Patangia](https://forum.biobakery.org/u/Dhrati_Patangia)\
**Post date:** [July 26, 2021, 10:37am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/19 "2021-07-26T10:37:05Z")

</div>

Hi, I am trying to use Maaslin2 and I have a significant results file generated which has many output results but only 10 figures in the figures folder. This is way less than the number of significant results written in the results file. Can you help?  
Thank you

Best  
DP

---

<div class="post-metadata">

**Author:** ![himel.mallick](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/himel.mallick/32/1757_2.png) [@himel.mallick](https://forum.biobakery.org/u/himel.mallick)\
**Post date:** [July 26, 2021, 10:56am UTC](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121/20 "2021-07-26T10:56:35Z")

</div>

Hi @Dhrati_Patangia - the figures generally are multi-page PDFs one for each metadata combined across significant features. In addition, for categorical variables, the p-values are usually pairwise whereas the figures are across all categories - hence more rows in the results table than the corresponding PDFs.

Does it make sense?

Best,  
Himel

[Next page](https://forum.biobakery.org/t/reference-values-for-a-categorical-fixed-effect-variable/1121.md?page=2)
