get_weights: Get weights

Description Usage Arguments Value Examples

View source: R/get_methods.R

Description

Extract the weights from the model.

Usage

1
2
3
4
5
6
7
8
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 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)

MOFA2 documentation built on Nov. 8, 2020, 7:28 p.m.