subset-NMF: Sub-setting NMF Objects

Description Usage Arguments Details Examples

Description

This method provides a convenient way of sub-setting objects of class NMF, using a matrix-like syntax.

Usage

1
2
## S4 method for signature 'NMF,ANY,ANY,ANY'
x[i, j, ..., drop = FALSE]

Arguments

x

an object that inherit from NMF.

i

index used to subset on the rows of the basis matrix (i.e. the features). It can be a numeric, logical, or character vector (whose elements must match the row names of x). In the case of a logical vector the entries are recycled if necessary.

j

index used to subset on the columns of the mixture coefficient matrix (i.e. the samples). It can be a numeric, logical, or character vector (whose elements must match the column names of x). In the case of a logical vector the entries are recycled if necessary.

...

used to specify a third index to subset on the basis components, i.e. on both the columns and rows of the basis matrix and mixture coefficient respectively. It can be a numeric, logical, or character vector (whose elements must match the basis names of x). In the case of a logical vector the entries are recycled if necessary.

Note that only the first extra subset index is used. A warning is thrown if more than one extra argument is passed in ....

drop

single logical value used to drop the NMF-class wrapping and only return subsets of one of the factor matrices (see Details)

Details

It allows to consistently subset one or both matrix factors in the NMF model, as well as retrieving part of the basis components or part of the mixture coefficients with a reduced amount of code.

The returned value depends on the number of subset index passed and the value of argument drop:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# create a dummy NMF object that highlight the different way of subsetting
a <- nmfModel(W=outer(seq(1,5),10^(0:2)), H=outer(10^(0:2),seq(-1,-10)))
basisnames(a) <- paste('b', 1:nbasis(a), sep='')
rownames(a) <- paste('f', 1:nrow(a), sep='')
colnames(a) <- paste('s', 1:ncol(a), sep='')

# or alternatively:
# dimnames(a) <- list( features=paste('f', 1:nrow(a), sep='')
#					, samples=paste('s', 1:ncol(a), sep='')
#					, basis=paste('b', 1:nbasis(a)) )

# look at the resulting NMF object 
a
basis(a)
coef(a)

# extract basis components
a[1]
a[1, drop=FALSE] # not dropping matrix dimension
a[2:3]

# subset on the features
a[1,]
a[2:4,]
# dropping the NMF-class wrapping => return subset basis matrix
a[2:4,, drop=TRUE]

# subset on the samples
a[,1]
a[,2:4]
# dropping the NMF-class wrapping => return subset coef matrix
a[,2:4, drop=TRUE]

# subset on the basis => subsets simultaneously basis and coef matrix
a[,,1]
a[,,2:3]
a[4:5,,2:3]
a[4:5,,2:3, drop=TRUE] # return subset basis matrix
a[,4:5,2:3, drop=TRUE] # return subset coef matrix

# 'drop' has no effect here
a[,,2:3, drop=TRUE]

renozao/NMF documentation built on June 14, 2020, 9:35 p.m.