get_weights: Get weights

View source: R/get_methods.R

get_weightsR Documentation

Get weights

Description

Extract the weights from the model.

Usage

get_weights(
  object,
  views = "all",
  factors = "all",
  abs = FALSE,
  scale = FALSE,
  as.data.frame = FALSE
)

Arguments

object

a trained MOFA object.

views

character vector with the view name(s), or numeric vector with the view index(es). Default is "all".

factors

character vector with the factor name(s) or numeric vector with the factor index(es).
Default is "all".

abs

logical indicating whether to take the absolute value of the weights.

scale

logical indicating whether to scale all weights from -1 to 1 (or from 0 to 1 if abs=TRUE).

as.data.frame

logical indicating whether to return a long data frame instead of a list of matrices. Default is FALSE.

Value

By default it returns a list where each element is a loading matrix with dimensionality (D,K), where D is the number of features and K is the number of factors.
Alternatively, if as.data.frame is TRUE, returns a long-formatted data frame with columns (view,feature,factor,value).

Examples

# Using an existing trained model on simulated data
file <- system.file("extdata", "model.hdf5", package = "MOFA2")
model <- load_model(file)

# Fetch weights in matrix format (a list, one matrix per view)
weights <- get_weights(model)

# Fetch weights for factor 1 and 2 and view 1
weights <- get_weights(model, views = 1, factors = c(1,2))

# Fetch weights in data.frame format
weights <- get_weights(model, as.data.frame = TRUE)

bioFAM/MOFA2 documentation built on June 12, 2024, 3:57 p.m.