In this chapter, we continue from where we left off in the previous chapter (Chapter 20). Instead of testing feature pairs one by one, we now look for patterns that are shared across the omic layers. We introduce two unsupervised integration methods: Joint Robust Principal Component Analysis (Joint-RPCA) (Cordazzo Vargas et al. 2026) and Multi-Omics Factor Analysis (MOFA) (Argelaguet et al. 2018).
Both methods are based on ordination, similar to principal component analysis (PCA) and principal coordinate analysis (PCoA) introduced in Chapter 13. They reduce the dimensionality of the data into a small number of components or factors that capture the main patterns of variation. Unlike in single-table ordination, these components are shared across the omic layers, and each feature in each layer gets a loading or weight on them. Features with large loadings on the same component co-vary across the samples.
However, the methods make different assumptions about the data:
Joint-RPCA extends robust PCA (RPCA) (Martino et al. 2019) to multiple tables. It assumes that the tables share an underlying low-rank structure that can be estimated with matrix completion (Keshavan et al. 2010). Microbiome data is transformed with the robust centered log-ratio (rclr) transformation, in which zeros are treated as missing values. This makes the method designed for sparse and compositional data. In the benchmarks of Cordazzo Vargas et al. (2026), Joint-RPCA recovered phenotype-associated structure more consistently than general-purpose multi-omics methods, including MOFA, under the sparse and compositional data conditions typical of microbiome studies.
MOFA is a probabilistic factor model that does not assume any microbiome-specific data properties. By default, it assumes normally distributed data, so the data is usually transformed and standardized beforehand. MOFA is a general-purpose method that is widely used in multi-omics studies across fields, and it is supported by a large set of tools and tutorials. When the data matches its assumptions, it can perform better than Joint-RPCA (Cordazzo Vargas et al. 2026).
A novel sparse compositional technique reveals microbial perturbations. Martino et al. (2019). mSystems 4:e00016–19. doi:10.1128/mSystems.00016-19.
Matrix completion from a few entries. Keshavan et al. (2010). IEEE Trans Inf Theory 56:2980–2998. doi:10.1109/TIT.2010.2046205.
21.1 Data
We use the Hintikka et al. (2021) dataset introduced in Chapter 19.
Xylo-oligosaccharides in prevention of hepatic steatosis and adipose tissue inflammation: Associating taxonomic and metabolomic patterns in fecal microbiomes with biclustering. Hintikka et al. (2021). Int J Environ Res Public Health 18:4049. doi:10.3390/ijerph18084049.
For Joint-RPCA, we agglomerate the microbiome data to genus level and filter the counts in three steps, in the same order as gemelli, the original Python implementation of Joint-RPCA: we remove genera with few reads, then genera that are present in few samples, and finally samples with few reads. Each step is computed from the data left by the previous step, so, for instance, library sizes are calculated after the rare genera are removed. Filtering must be done on untransformed counts. Then, we apply the rclr transformation. We set impute = FALSE, because Joint-RPCA handles the zeros, i.e., missing values, itself through matrix completion. The metabolite concentrations are log10-transformed. The biomarker data contains zeros, so instead of a log transformation, we standardize each biomarker.
# Agglomerate microbiome datamae[["microbiota"]]<-agglomerateByRank(mae[["microbiota"]], rank ="Genus")# Remove the "D_5__" prefix of the SILVA genus names to shorten the labelsrownames(mae[["microbiota"]])<-sub("^D_5__", "", rownames(mae[["microbiota"]]))# Filter the raw counts in stepstse<-mae[["microbiota"]]# 1. Remove genera with 10 reads or fewer in totaltse<-tse[rowSums(assay(tse, "counts"))>10, ]# 2. Remove genera that are present in 10% or less of the samplestse<-tse[rowMeans(assay(tse, "counts")>0)>0.1, ]# 3. Remove samples with 1000 reads or fewertse<-tse[, colSums(assay(tse, "counts"))>1000]mae[["microbiota"]]<-tse# Apply rclr transformation without imputing zerosmae[["microbiota"]]<-transformAssay(mae[["microbiota"]], method ="rclr", impute =FALSE)# Apply log10 transformation to metabolome NMR assaymae[["metabolites"]]<-transformAssay(mae[["metabolites"]], assay.type ="nmr", method ="log10")# Standardize biomarker assaymae[["biomarkers"]]<-transformAssay(mae[["biomarkers"]], assay.type ="signals", method ="standardize", MARGIN ="rows")
Note: Filtering with mia functions
The metrics can also be calculated with getPrevalence() and addQC() from mia. If so, recalculate them after each step: metrics calculated once from the original object ignore the earlier steps, e.g., library sizes would still include the reads of the removed genera.
21.2 Joint-RPCA
Joint-RPCA (joint robust principal component analysis) (Cordazzo Vargas et al. 2026) is available in mia and its results can be visualized with miaViz. We run the analysis with addJointRPCA(), which stores the results in the metadata of the MultiAssayExperiment(Ramos et al. 2017).
Joint-RPCA: Domain-aware multi-omics integration for systems microbiology. Cordazzo Vargas et al. (2026). Mol Syst Biol 22:1789–1808. doi:10.1038/s44320-026-00236-3.
Software for the integration of multiomics experiments in Bioconductor. Ramos et al. (2017). Cancer Res 77:e39–e42. doi:10.1158/0008-5472.CAN-17-0344.
The explained variance is visualized with plotJointRPCAExplainedVariance(). The heatmap shows how the variance of each omic layer is divided across the components, and the barplot shows how the total variance is divided across the layers. Note that the values describe the low-rank Joint-RPCA model, not the proportion of variance explained in the observed data (Figure 21.1).
Figure 21.1: Variance explained by the Joint-RPCA model of the Hintikka et al. (2021) data. The heatmap shows the variance of each omic layer (microbiota, metabolites, biomarkers) explained by each of the five components, and the barplot shows the share of total variance per layer.
As in other ordination methods, the samples can be visualized in the space of the first two components (Figure 21.2).
Figure 21.2: Joint-RPCA sample scores of the Hintikka et al. (2021) data on the first two components, colored by diet.
We can then visualize the features with the largest loadings in each omic layer for the first two components to analyze co-varying features (Figure 21.3).
Figure 21.3: Top 10 features with the largest Joint-RPCA loadings on the first two components in each omic layer (microbiota genera, metabolites and biomarkers) of the Hintikka et al. (2021) data.
In addition to the loadings, the co-variation can be visualized directly as correlations between features both within and across the omic layers. The correlations are calculated from the Joint-RPCA model, and they reflect how the features align in the Joint-RPCA space rather than correlations in the observed data (Figure 21.4).
Figure 21.4: Heatmap of correlations between the top features of the microbiota, metabolite and biomarker layers, derived from the Joint-RPCA model of the Hintikka et al. (2021) data.
The same information can be visualized as a network, where the edges connect strongly correlated features (Figure 21.5).
Figure 21.5: Network of features from the microbiota, metabolite and biomarker layers based on the Joint-RPCA model of the Hintikka et al. (2021) data. Edges connect strongly correlated features.
21.3 MOFA
Multi-Omics Factor Analysis (MOFA) is an unsupervised method for integrating multi-omic datasets in a downstream analysis (Argelaguet et al. 2018). It could be seen as a generalization of principal component analysis, with the ability to infer a latent (low-dimensional) representation shared among the multiple (-omics) datasets in hand.
Multi-omics factor analysis—a framework for unsupervised integration of multi-omics data sets. Argelaguet et al. (2018). Mol Syst Biol 14:e8124. doi:10.15252/msb.20178124.
MOFA+: A statistical framework for comprehensive integration of multi-modal single-cell data. Argelaguet et al. (2020). Genome Biol 21:111. doi:10.1186/s13059-020-02015-1.
library(mia)# Import datasetdata("HintikkaXOData", package ="mia")# Store as maemae<-HintikkaXOData
The mae object could be used directly to create the MOFA model. Yet, we transform our assays since the model assumes normality by default, and the Gaussian model is recommended (see MOFA2 FAQ). However, Poisson and Bernoulli distribution models are also available.
Then, we create the MOFA model with mofa2(). Data, model and training options can be given as additional arguments; otherwise, defaults are used (see ?mofa2).
# Build MOFA2 modelmodel<-mofa2(mae, experiments =c("microbiota", "metabolites", "biomarkers"), assays =c("clr-z", "log10-z", "z"), num_factors =5)# View modelmodel## Untrained MOFA model with the following characteristics: ## Number of views: 3 ## Views names: microbiota metabolites biomarkers ## Number of features (per view): 112 38 39 ## Number of groups: 1 ## Groups names: group1 ## Number of samples (per group): 40 ##
# Some systems may require the specification `use_basilisk = TRUE`# so it has been added to the following codemodel<-run_mofa(model, use_basilisk =TRUE)
Figure 21.6: Variance explained by the MOFA model of the Hintikka et al. (2021) data. The heatmap shows the variance explained per factor (rows) and omic layer (columns), and the barplot shows the total variance explained per layer.
Similarly to Joint-RPCA, the samples can be visualized in the space of the first two factors (Figure 21.7).
Figure 21.8: Top 10 features with the largest absolute MOFA weights on factors 1 and 2 for the microbiota (top) and metabolite (bottom) layers of the Hintikka et al. (2021) data.
More tutorials and examples of using the package are found at MOFA2 tutorials.
Solve the exercises in order, as each exercise continues from the previous one. Try to solve each exercise yourself before opening the solution.
Exercise 1: Shared components
Goal: Explain what the ordination-based integration methods estimate and how Joint-RPCA and MOFA differ.
Answer the following questions without writing any code. The beginning of this chapter will help you.
How do Joint-RPCA and MOFA differ from a PCA that is run on a single table?
A bacterial genus and a metabolite both have a large positive loading on the first component. What does this tell about them?
How does the rclr transformation used in Joint-RPCA handle zeros? Why does this suit microbiome data?
Why is the data usually transformed and standardized before running MOFA?
Solution
Like PCA, they reduce the data into a small number of components or factors that capture the main patterns of variation. Unlike in single-table PCA, the components are shared across the omic layers, and each feature in each layer gets a loading or weight on them.
Features with large loadings on the same component co-vary across the samples. Here, samples with a high score on the first component tend to have high values of both the genus and the metabolite.
The rclr transformation treats zeros as missing values, and Joint-RPCA estimates them with matrix completion. Microbiome data is sparse and compositional, so it has many zeros that may not be true absences. The method is designed for these properties.
By default, MOFA assumes normally distributed data, and it does not assume any microbiome-specific properties. The transformations make the data closer to normal, and the standardization puts all features on the same scale.
Exercise 2: Prepare the data for Joint-RPCA
Goal: Prepare multi-omic data for Joint-RPCA.
Load the HintikkaXOData dataset from the mia package and store it in a variable called mae.
Check which experiments the dataset contains and which assays each experiment has.
Agglomerate the microbiota data to genus level.
Filter the counts assay of the microbiota data in three steps: remove the genera with 10 reads or fewer in total, then the genera that are present in 10% or less of the samples, and finally the samples with 1000 reads or fewer. How many genera and samples remain?
Apply the rclr transformation to the microbiota data without imputing the zeros (impute = FALSE).
Count the zeros in the counts assay and the missing values in the rclr assay of the microbiota data. Compare the two numbers.
Apply the log10 transformation to the nmr assay of the metabolites, and standardize each biomarker in the signals assay.
library(mia)# 1. Load the datadata("HintikkaXOData", package ="mia")mae<-HintikkaXOData# 2. Experiments and their assaysexperiments(mae)## ExperimentList class object of length 3:## [1] microbiota: TreeSummarizedExperiment with 12706 rows and 40 columns## [2] metabolites: TreeSummarizedExperiment with 38 rows and 40 columns## [3] biomarkers: TreeSummarizedExperiment with 39 rows and 40 columnsassayNames(mae[["microbiota"]])## [1] "counts"assayNames(mae[["metabolites"]])## [1] "nmr"assayNames(mae[["biomarkers"]])## [1] "signals"# 3. Agglomerate the microbiota data to genus levelmae[["microbiota"]]<-agglomerateByRank(mae[["microbiota"]], rank ="Genus")rownames(mae[["microbiota"]])<-sub("^D_5__", "", rownames(mae[["microbiota"]]))# 4. Filter the counts in three stepstse<-mae[["microbiota"]]tse<-tse[rowSums(assay(tse, "counts"))>10, ]tse<-tse[rowMeans(assay(tse, "counts")>0)>0.1, ]tse<-tse[, colSums(assay(tse, "counts"))>1000]mae[["microbiota"]]<-tsedim(mae[["microbiota"]])## [1] 142 40# 5. rclr transformation without imputing zerosmae[["microbiota"]]<-transformAssay(mae[["microbiota"]], method ="rclr", impute =FALSE)# 6. Zeros in counts and missing values in rclrsum(assay(mae[["microbiota"]], "counts")==0)## [1] 1447sum(is.na(assay(mae[["microbiota"]], "rclr")))## [1] 1447# 7. Transform metabolites and biomarkersmae[["metabolites"]]<-transformAssay(mae[["metabolites"]], assay.type ="nmr", method ="log10")mae[["biomarkers"]]<-transformAssay(mae[["biomarkers"]], assay.type ="signals", method ="standardize", MARGIN ="rows")
dim() shows the number of remaining genera and samples. No samples are removed by the last step.
The two numbers are equal, because each zero in the counts becomes a missing value in the rclr assay. Joint-RPCA estimates these missing values itself.
Exercise 3: Run Joint-RPCA
Goal: Run Joint-RPCA and visualize the explained variance and the samples.
Set the seed to 123 and run Joint-RPCA with addJointRPCA() on all three experiments. Use the assays rclr, log10 and standardize, and three components (ncomponents = 3).
Show the first sample scores, which are stored in metadata(mae).
Visualize the explained variance.
Plot the samples in the space of the first two components, and color them by Diet.
How do you read the explained variance plot? How can you see from the sample plot whether the diet groups differ?
# 4. Samples colored by dietplotJointRPCA(mae, "JointRPCA", colour.by ="Diet")
The heatmap shows how the variance of each omic layer is divided across the components, and the barplot shows how the total variance is divided across the layers. A component that explains much variance in several layers captures a pattern that is shared by them. Note that the values describe the low-rank Joint-RPCA model, not the observed data. In the sample plot, each point is a sample. If the colors form separate groups along a component, that component captures differences between the diet groups.
Exercise 4: Co-varying features in Joint-RPCA
Goal: Find features that co-vary across the omic layers.
Visualize the ten features with the largest loadings on the first two components in each omic layer.
Visualize the correlations between the top ten features of each layer as a heatmap (ntop = 10, correlation = TRUE).
Visualize the same correlations as a network with feature labels.
How do you read the heatmap and the network? Are these correlations calculated from the observed data?
# 1. Top loadings in each omic layerplotJointRPCALoadings(mae, "JointRPCA", ncomponents =2, n =10)
# 2. Correlations between the top features as a heatmapplotJointRPCACovariance(mae, "JointRPCA", ntop =10, correlation =TRUE)
# 3. Correlations as a networkplotJointRPCANetwork(mae, "JointRPCA", show.label =TRUE)
In the heatmap, each cell shows the correlation between two features, both within and across the omic layers. Positive values mean that the features increase together, and negative values that one increases when the other decreases. In the network, the nodes are features and the edges connect strongly correlated features. The correlations are not calculated from the observed data. They are derived from the Joint-RPCA model and describe how the features align in the Joint-RPCA space.
Exercise 5: Run MOFA
Goal: Prepare the data for MOFA, train the model and visualize the results.
Load HintikkaXOData again and store it in mae, so that you start from the original data.
Agglomerate the microbiota data to the Genus rank. Then add the prevalence, and combine the genera with a prevalence of 0.5 or less into “Other”. Apply the CLR transformation (Fernandes et al. 2014) with a pseudocount of 0.5, and then standardize each genus. Store the standardized assay under the name "clr-z".
Apply the log10 transformation to the nmr assay of the metabolites, and then standardize each metabolite. Store the standardized assay under the name "log10-z".
Standardize each biomarker in the signals assay, and store the result under the name "z".
Create a MOFA model with mofa2() from the three experiments and the assays clr-z, log10-z and z, with three factors (num_factors = 3). Train the model with run_mofa() and use_basilisk = TRUE.
Visualize the explained variance per factor and omic layer, with the layers on the x-axis and the factors on the y-axis. Then, in a separate plot, visualize the total variance explained in each layer.
Plot the samples in the space of the first two factors, and color them by Diet.
Visualize the ten features with the largest weights on the first two factors for the microbiota. Then make the same plot for the metabolites.
Compare the sample plot and the top features to those from Joint-RPCA in Exercises 3 and 4. Why might the two methods give different results?
library(MOFA2)# 1. Load the original datadata("HintikkaXOData", package ="mia")mae<-HintikkaXOData# 2. Microbiota: prevalent genera, CLR and standardizationmae[["microbiota"]]<-agglomerateByRank(mae[["microbiota"]], rank ="Genus")rownames(mae[["microbiota"]])<-sub("^D_5__", "", rownames(mae[["microbiota"]]))mae[["microbiota"]]<-addPrevalence(mae[["microbiota"]])mae[["microbiota"]]<-subsetBy(mae[["microbiota"]], rows =prevalence>0.5, collapse =TRUE)mae[["microbiota"]]<-transformAssay(mae[["microbiota"]], method ="clr", pseudocount =0.5)mae[["microbiota"]]<-transformAssay(mae[["microbiota"]], assay.type ="clr", method ="standardize", MARGIN ="rows", name ="clr-z")# 3. Metabolites: log10 and standardizationmae[["metabolites"]]<-transformAssay(mae[["metabolites"]], assay.type ="nmr", method ="log10")mae[["metabolites"]]<-transformAssay(mae[["metabolites"]], assay.type ="log10", method ="standardize", MARGIN ="rows", name ="log10-z")# 4. Biomarkers: standardizationmae[["biomarkers"]]<-transformAssay(mae[["biomarkers"]], assay.type ="signals", method ="standardize", MARGIN ="rows", name ="z")# 5. Create and train the MOFA modelmodel<-mofa2(mae, experiments =c("microbiota", "metabolites", "biomarkers"), assays =c("clr-z", "log10-z", "z"), num_factors =3)model<-run_mofa(model, use_basilisk =TRUE)
# 6. Explained variance per factor and layer, and in totalplot_list<-plot_variance_explained(model, x ="view", y ="factor", plot_total =TRUE)plot_list[[1]]
Compare whether the diet groups are separated along the first components or factors in both methods, and which features have the largest loadings or weights in both. Note that the sign and order of the components can differ between the methods. The methods can give different results, because they use different transformations and assumptions. Joint-RPCA uses the rclr transformation, treats zeros as missing values and is designed for sparse and compositional data. MOFA assumes normally distributed data, and the microbiota data was CLR-transformed with a pseudocount and standardized. Also the filtering of the genera differed between the methods.
Unifying the analysis of high-throughput sequencing datasets: Characterizing RNA-seq, 16S rRNA gene sequencing and selective growth experiments by compositional data analysis. Fernandes et al. (2014). Microbiome 2:15. doi:10.1186/2049-2618-2-15.