get_expectations: Get expectations

View source: R/get_methods.R

get_expectationsR Documentation

Get expectations


Function to extract the expectations from the (variational) posterior distributions of a trained MOFA object.


get_expectations(object, variable, = FALSE)



a trained MOFA object.


variable name: 'Z' for factors and 'W' for weights.

logical indicating whether to output the result as a long data frame, default is FALSE.


Technical note: MOFA is a Bayesian model where each variable has a prior distribution and a posterior distribution. In particular, to achieve scalability we used the variational inference framework, thus true posterior distributions are replaced by approximated variational distributions. This function extracts the expectations of the variational distributions, which can be used as final point estimates to analyse the results of the model.
The priors and variational distributions of each variable are extensively described in the supplementary methods of the original paper.


the output varies depending on the variable of interest:

  • "Z"a matrix with dimensions (samples,factors). If is TRUE, a long-formatted data frame with columns (sample,factor,value)

  • "W"a list of length (views) where each element is a matrix with dimensions (features,factors). If is TRUE, a long-formatted data frame with columns (view,feature,factor,value)


# Using an existing trained model
file <- system.file("extdata", "model.hdf5", package = "MOFA2")
model <- load_model(file)
factors <- get_expectations(model, "Z")
weights <- get_expectations(model, "W")

bioFAM/MOFA2 documentation built on March 21, 2023, 5:27 p.m.