Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nmfApply

Apply Function for NMF Objects


Description

The function nmfApply provides exteneded apply-like functionality for objects of class NMF. It enables to easily apply a function over different margins of NMF models.

Usage

nmfApply(X, MARGIN, FUN, ..., simplify = TRUE,
    USE.NAMES = TRUE)

Arguments

X

an object that has suitable basis and coef methods, e.g. an NMF model.

MARGIN

a single numeric (integer) value that specifies over which margin(s) the function FUN is applied. See section Details for a list of possible values.

FUN

a function to apply over the specified margins.

...

extra arguments passed to FUN

simplify

a logical only used when MARGIN=3, that indicates if sapply should try to simplify result if possible. Since this argument follows ‘...’ its name cannot be abbreviated.

USE.NAMES

a logical only used when MARGIN=3, that indicates if sapply should use the names of the basis components to name the results if present. Since this argument follows ‘...’ its name cannot be abbreviated.

Details

The function FUN is applied via a call to apply or sapply according to the value of argument MARGIN as follows:

MARGIN=1

apply FUN to each row of the basis matrix: apply(basis(X), 1L, FUN, ...).

MARGIN=2

apply FUN to each column of the coefficient matrix: apply(coef(X), 2L, FUN, ...).

MARGIN=3

apply FUN to each pair of associated basis component and basis profile: more or less sapply(seq(nbasis(X)), function(i, ...) FUN(basis(X)[,i], coef(X)[i, ], ...), ...).

In this case FUN must be have at least two arguments, to which are passed each basis components and basis profiles respectively – as numeric vectors.

MARGIN=4

apply FUN to each column of the basis matrix, i.e. to each basis component: apply(basis(X), 2L, FUN, ...).

MARGIN=5

apply FUN to each row of the coefficient matrix: apply(coef(X), 1L, FUN, ...).

Value

a vector or a list. See apply and sapply for more details on the output format.


NMF

Algorithms and Framework for Nonnegative Matrix Factorization (NMF)

v0.23.0
GPL (>= 2)
Authors
Renaud Gaujoux, Cathal Seoighe
Initial release
2020-07-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.