Longitudinal and Complex Association Testing with MaAsLin3
MaAsLin3 (Multivariate Association with Linear Models) enables complex modeling of associations between microbial features and metadata using R’s lme4
formula syntax. The Cosmos-Hub automatically translates user-selected variables into valid MaAsLin3 formulas, supporting a wide range of study designs. This extends beyond the typical “Fixed” and “Random” effects by implementing other variables such as:
Basic Formula Components
Fixed Effects (Simple relationships)
This means: “Model the abundance of each feature as influenced by diet, age, and sex.”
This will perform the same function as adding each variable as a fixed effect in the standard GUI.
Each variable is assumed to have an independent effect on the microbial feature’s abundance and/or prevalence.
Interaction Terms
Expands to:
This tests if the effect of diet is different between males and females.
Random Effects (Repeated Measures or Hierarchies)
This tells MaAsLin3: “Model treatment effects, while accounting for multiple samples from the same subject.”
Random effects help control for non-independence of observations (e.g., same person measured over time).
Multiple random effects are supported:
Group, Ordered, and Strata Variables
Note: Group/ordered predictors should not appear in random effects.
Only one strata variable can be used in a model:
Example
Let’s say you’re analyzing a microbiome dataset of gut samples from different diets, ages, and sexes, with repeated sampling across time:
This means:
- Main effects of diet, sex, age
- Diet × sex interaction
- Random effect for individual subjects
If you’re doing a matched study (e.g., pre/post), you could use:
Formula Scenarios
Scenario | Formula Syntax | Description | |
---|---|---|---|
Fixed Effects | ~ diet + age | Basic effects of variables like diet or age | |
Random Effects | `~ diet + (1 | subject_id)` | Accounts for repeated measurements within individuals |
Interaction Terms | ~ diet * sex | Tests whether the effect of one variable depends on another | |
Fixed + Random + Interaction | `~ diet * sex + (1 | subject_id)` | Full model with main, interaction, and repeated effects |
Group Effects | ~ group(diet) | Treats all levels of a categorical variable jointly | |
Ordered Effects | ~ ordered(stage) | Tests stepwise effects in ordinal variables (e.g., Stage I < II < III) | |
Strata Effects (Exclusive) | ~ strata(pair_id) | For matched case-control studies (cannot be combined with other effects) |
Combining Effect Types
Effect types can often be mixed—except strata, which must stand alone:
Combination | Example | |
---|---|---|
Fixed + Random | `~ age + (1 | subject_id)` |
Fixed + Interaction | ~ age + treatment + age:treatment | |
Fixed + Group | ~ group(treatment) + age | |
Fixed + Ordered | ~ ordered(dose_level) + age | |
Fixed + Random + Group | `~ group(treatment) + age + (1 | subject_id)` |
Fixed + Random + Interaction | `~ treatment * timepoint + (1 | subject_id)` |
Strata Only | ~ strata(pair_id) |
Syntax Notes
- Interaction Terms:
var1:var2
models whether the effect ofvar1
changes acrossvar2
. - Group Effects:
group(var)
aggregates all levels for joint testing. - Ordered Effects:
ordered(var)
evaluates progression across ordered categories. - Strata Effects:
strata(var)
conditions the analysis on matched groups (e.g., case-control pairs) and cannot be combined with other effects.
Cosmos-Hub Smart Formula Handling
- Automatic parsing: Your selections in the Cosmos-Hub interface are converted into the correct formula string.
- Validation: Invalid or unsupported combinations (e.g., using
strata
withrandom
) are flagged before submission. - Support for prevalence and abundance.
Key Considerations
- Strata must be the only term in the formula—no other variables allowed.
- Group and ordered variables behave like fixed effects but are tested differently.
- Interaction models are essential for longitudinal or treatment-timepoint designs.