dimnames: Dimension names for NMF objects

basisnamesR Documentation

Dimension names for NMF objects

Description

The methods dimnames, rownames, colnames and basisnames and their respective replacement form allow to get and set the dimension names of the matrix factors in a NMF model.

dimnames returns all the dimension names in a single list. Its replacement form dimnames<- allows to set all dimension names at once.

rownames, colnames and basisnames provide separate access to each of these dimension names respectively. Their respective replacement form allow to set each dimension names separately.

Usage

  basisnames(x, ...)

  basisnames(x, ...)<-value

  ## S4 method for signature 'NMF'
dimnames(x)

  ## S4 replacement method for signature 'NMF'
dimnames(x)<-value

Arguments

x

an object with suitable basis and coef methods, such as an object that inherit from NMF.

...

extra argument to allow extension.

value

a character vector, or NULL or, in the case of dimnames<-, a list 2 or 3-length list of character vectors.

Details

The function basisnames is a new S4 generic defined in the package NMF, that returns the names of the basis components of an object. Its default method should work for any object, that has a suitable basis method defined for its class.

The method dimnames is implemented for the base generic dimnames, which make the base function rownames and colnames work directly.

Overall, these methods behave as their equivalent on matrix objects. The function basisnames<- ensures that the dimension names are handled in a consistent way on both factors, enforcing the names on both matrix factors simultaneously.

The function basisnames<- is a new S4 generic defined in the package NMF, that sets the names of the basis components of an object. Its default method should work for any object, that has suitable basis<- and coef<- methods method defined for its class.

Methods

basisnames

signature(x = "ANY"): Default method which returns the column names of the basis matrix extracted from x, using the basis method.

For NMF objects these also correspond to the row names of the coefficient matrix.

basisnames<-

signature(x = "ANY"): Default method which sets, respectively, the row and the column names of the basis matrix and coefficient matrix of x to value.

dimnames

signature(x = "NMF"): Returns the dimension names of the NMF model x.

It returns either NULL if no dimnames are set on the object, or a 3-length list containing the row names of the basis matrix, the column names of the mixture coefficient matrix, and the column names of the basis matrix (i.e. the names of the basis components).

dimnames<-

signature(x = "NMF"): sets the dimension names of the NMF model x.

value can be NULL which resets all dimension names, or a 1, 2 or 3-length list providing names at least for the rows of the basis matrix.

The optional second element of value (NULL if absent) is used to set the column names of the coefficient matrix. The optional third element of value (NULL if absent) is used to set both the column names of the basis matrix and the row names of the coefficient matrix.

Examples



# create a random NMF object
a <- rnmf(2, 5, 3)

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

# access the dimensions separately
rownames(a)
colnames(a)
basisnames(a)

# set only the first dimension (rows of basis): the other two dimnames are set to NULL
dimnames(a) <- dims[1]
dimnames(a)
basis(a)
coef(a)

# set only the two first dimensions (rows and columns of basis and coef respectively):
# the basisnames are set to NULL
dimnames(a) <- dims[1:2]
dimnames(a)
basis(a)

# reset the dimensions
dimnames(a) <- NULL
dimnames(a)
basis(a)
coef(a)

# set each dimensions separately
rownames(a) <- paste('X', 1:nrow(a), sep='') # only affect rows of basis
basis(a)

colnames(a) <- paste('Y', 1:ncol(a), sep='') # only affect columns of coef
coef(a)

basisnames(a) <- paste('Z', 1:nbasis(a), sep='') # affect both basis and coef matrices
basis(a)
coef(a)

NMF documentation built on March 31, 2023, 6:55 p.m.