Using Maaslin2 function to regress out the effect of subject

Hi, First of all thank you for providing such a wonderful tool.
I am looking to use this function to regress out the effect of certain variables on microbiome data. For example with the data available with the library, let’s say I want to remove the effect of ‘age’ and ‘subject’ so that the cleaned data can be used for downstream analysis like machine learning and network analysis. Is the approach below valid way to do so?


##Read system files
input_data = system.file(
  "extdata", "HMP2_taxonomy.tsv", package="Maaslin2") # The abundance table file
input_metadata = system.file(
  "extdata", "HMP2_metadata.tsv", package="Maaslin2") # The metadata table file

df_input_data = read.table(file = input_data, header = TRUE, sep = "\t",
                           row.names = 1,
                           stringsAsFactors = FALSE)
df_input_data[1:5, 1:5]
df_input_metadata = read.table(file = input_metadata, header = TRUE, sep = "\t",
                               row.names = 1,
                               stringsAsFactors = FALSE)
df_input_metadata[1:5, ]

##To regress out 'age' and 'subject' build model with 'age' as fixed effect and 'subject' as fixed effect
fit_data3 = Maaslin2(
  input_data = df_input_data, 
  input_metadata = df_input_metadata, 
  output = "demo_output3", 
  fixed_effects = c("age"),
  random_effects = c("subject"))

cleaned_data <- fit_data3$residuals

If this is proper method how can I use both age and subject as random effects ie without any fixed effects ? Your suggestions and pointers will be highly appreciated.

Thank you

Hi there,

It looks like you are on the right track here.

Unfortunately, Maaslin2 does not support a model without any fixed effects in it as we didn’t anticipate this use case. In theory you may be able to introduce a dummy fixed effect to get around this.

In future releases we will keep this use case in mind.

Jacob Nearing

Thank you. This is very helpful.