basis
Accessing NMF Factors
basis
and basis<-
are S4 generic functions
which respectively extract and set the matrix of basis
components of an NMF model (i.e. the first matrix
factor).
The methods .basis
, .coef
and their
replacement versions are implemented as pure virtual
methods for the interface class NMF
, meaning that
concrete NMF models must provide a definition for their
corresponding class (i.e. sub-classes of class
NMF
). See
for more
details.
coef
and coef<-
respectively extract and
set the coefficient matrix of an NMF model (i.e. the
second matrix factor). For example, in the case of the
standard NMF model $V \equiv WH$, the method
coef
will return the matrix $H$.
.coef
and .coef<-
are low-level S4 generics
that simply return/set coefficient data in an object,
leaving some common processing to be performed in
coef
and coef<-
.
Methods coefficients
and coefficients<-
are
simple aliases for methods coef
and coef<-
respectively.
scoef
is similar to coef
, but returns the
mixture coefficient matrix of an NMF model, with the
columns scaled so that they sum up to a given value (1 by
default).
- Keywords
- methods
Usage
basis(object, ...) ## S3 method for class 'NMF':
basis(object, all = TRUE, ...)
.basis(object, ...)
basis(object) <- value
.basis(object) <- value
## S3 method for class 'NMF':
loadings(x)
coef(object, ...)
## S3 method for class 'NMF':
coef(object, all = TRUE, ...)
.coef(object, ...)
coef(object) <- value
.coef(object) <- value
coefficients(object, ...)
## S3 method for class 'NMF':
coefficients(object, all = TRUE, ...)
scoef(object, ...)
## S3 method for class 'NMF':
scoef(object, scale = 1)
## S3 method for class 'matrix':
scoef(object, scale = 1)
Arguments
- object
- an object from which to extract the factor
matrices, typically an object of class
.NMF - ...
- extra arguments to allow extension and passed
to the low-level access functions
.coef
and.basis
. - all
- a logical that indicates whether the complete
matrix factor should be returned (
TRUE
) or only the non-fixed part. This is relevant only for formula-based NMF models that include fixed basis or coefficient terms. - value
- replacement value
- scale
- scaling factor, which indicates to the value the columns of the coefficient matrix should sum up to.
- x
- an object of class
"factanal"
or"princomp"
or theloadings
component of such an object.
Details
For example, in the case of the standard NMF model $V
\equiv W H$, the method basis
will return
the matrix $W$.
basis
and basis<-
are defined for the top
virtual class
only, and rely
internally on the low-level S4 generics .basis
and
.basis<-
respectively that effectively extract/set
the coefficient data. These data are post/pre-processed,
e.g., to extract/set only their non-fixed terms or check
dimension compatibility.
coef
and coef<-
are S4 methods defined for
the corresponding generic functions from package
stats
(See coef). Similarly to
basis
and basis<-
, they are defined for the
top virtual class
only, and rely
internally on the S4 generics .coef
and
.coef<-
respectively that effectively extract/set
the coefficient data. These data are post/pre-processed,
e.g., to extract/set only their non-fixed terms or check
dimension compatibility.
See Also
Other NMF-interface:
.DollarNames,NMF-method
,
misc
, NMF-class
,
$<-,NMF-method
, $,NMF-method
,
nmfModel
, nmfModels
,
rnmf
Examples
# Scaled coefficient matrix
x <- rnmf(3, 10, 5)
scoef(x)
scoef(x, 100)
# random standard NMF model
x <- rnmf(3, 10, 5)
basis(x)
coef(x)
# set matrix factors
basis(x) <- matrix(1, nrow(x), nbasis(x))
coef(x) <- matrix(1, nbasis(x), ncol(x))
# set random factors
basis(x) <- rmatrix(basis(x))
coef(x) <- rmatrix(coef(x))
# incompatible matrices generate an error:
try( coef(x) <- matrix(1, nbasis(x)-1, nrow(x)) )
# but the low-level method allow it
.coef(x) <- matrix(1, nbasis(x)-1, nrow(x))
try( validObject(x) )