feemparafac forwards its arguments to parafac
from the multiway package, optionally rescales the result
and attaches a few attributes. Resulting objects of class
feemparafac can be accessed using methods presented below.
feemparafac(
X, ..., const = rep('nonneg', 3),
rescale = 3, retries = 10, subset = TRUE, envir = NULL
)
# S3 method for feemparafac
plot(x, type = c("image", "lines"), ...)
# S3 method for feemparafac
coef(
object, type = c(
"all", "scores", "loadings", "emission", "excitation", "samples"
), ...
)
# S3 method for feemparafac
fitted(object, ...)
# S3 method for feemparafac
residuals(object, ...)
An object of classes feemparafac and parafac with the
following attributes added:
A copy of the X argument.
A copy of the subset argument.
A copy of the envir argument.
rownames are added from the original data cube to
the A, B, C components of the list returned
by parafac.
Use feemcube on the return value to access the original
data cube.
A lattice plot object. Its print or plot
method will draw the plot on an appropriate plotting device.
A data.frame or a list of them (only if type
is “all”). See the description of the type argument
for more information.
A feemcube object comparable to X as it was
decomposed by parafac, ignoring the scaling.
A feemcube object equal to \(
\mathbf{X} - \hat{\mathbf{X}}
\), with an additional
class feem.resid set. Objects of this class are plotted with
a different default palette, see plot.feem.resid.
A FEEM cube object. The per-sample factors will be multiplied by
attr(X, 'scales') stored in it.
If envir is NULL (by default), this should be just a
value. If envir is given, this should be a name of the value
to get from the environment.
Passed as-is to parafac.
Passed as-is to lattice functions
levelplot and xyplot.
No other parameters are allowed.
A character vector of length 3 specifying the constraints for all
modes of X, passed to parafac. Defaults to
non-negativity. See const for more information.
Rescale the resulting factors to leave all the variance in the given
mode: emission, excitation, or sample (default). Set to NA
to disable.
Retry for given number of tries until parafac returns
a successfully fitted model or stops due to the iteration number
limit. Raise a fatal error if all tries were unsuccessful.
An integer or logical vector choosing the samples from X, as
in feemparafac(X[,,subset], ...). Defaults to the whole cube.
An environment to look up X in.
An object returned by feemparafac.
Given a fitted PARAFAC model:
$$ X_{i,j,k} = \sum_r A_{i,r} B_{j,r} C_{k,r} $$
With \(\mathbf{A}\) corresponding to fluorescence emission loadings, \(\mathbf{B}\) corresponding to fluorescence excitation loadings, and \(\mathbf{C}\) corresponding to the scores of the components in different samples, the following plots can be produced:
Plot the factors (“loadings”) as a series of pseudo-colour images of outer products \( \mathbf{a}_r \times \mathbf{b}_r^\top \)
Plot the factors \(\mathbf a_r\) and \(\mathbf b_r\) as functions of wavelengths, with each pair of factors on a different panel.
Fitted PARAFAC coefficients can be returned in the following forms:
Return the contents of \(\mathbf{A}\),
\(\mathbf{B}\) or \(\mathbf{C}\),
respectively, as a data.frame with three
columns, the first one (named wavelength or sample)
containing the independent variable
(\(\lambda_\mathrm{em}\) /
\(\lambda_\mathrm{ex}\) /
sample name or number),
the second one (named value) containing the values and
the third one (named factor) containing the factor numbers.
Same as samples.
Same as “emission” and “excitation” combined using
rbind, with a fourth column (mode) added,
naming the kinds of loadings.
A list with names “emission”, “excitation”,
“samples” containing results of
coef(object, "emission"), coef(object, "excitation"),
coef(object, "samples"), respectively.
feemparafac tries hard to guarantee the convergence flag to be
0 (normal convergence) or 1 (iteration number limit
reached), but never 2 (a problem with the constraints). A fatal
error is raised if repeated runs of parafac do not
return a (semi-)successfully fitted model.
After the PARAFAC decomposition is calculated, the scores are
multiplied by the scales attribute of the X object,
making them represent the cube with scaling undone. Use
feemscale(remember = FALSE) if you don't want to undo
the scaling.
The output option is fixed to "best" value. Obtaining
a list of alternative solutions can therefore be achieved by running:
replicate(n, feemparafac(..., nstart = 1), simplify = FALSE)
The subset and envir options are useful to repeatedly
perform PARAFAC on different subsets of the same FEEM cube, e.g. in
jack-knifing or split-half analysis. Since feemparafac keeps
a reference to the its X and envir arguments, the use
of subset should ensure that the same FEEM cube is referenced
from multiple feemparafac objects instead of creating copies
of its subsets. Additionally, environment objects are not duplicated
on save or load, so storing X in an
environment and passing it to multiple invocations of feemparafac
will save a lot of memory when the results are serialised together.
plot.feemparafac provides sane defaults for lattice
options such as xlab, ylab, as.table,
auto.key, type, cuts, col.regions, but
they can be overridden.
tools::toRd(bibentry('Article', author = person('Rasmus', 'Bro'), title = 'PARAFAC. Tutorial and applications', journal = 'Chemometrics and Intelligent Laboratory Systems', volume = 38, number = 2, pages = '149-171', year = 1997, doi = '10.1016/S0169-7439(97)00032-4' ))
parafac class structure;
write.openfluor, feemcube for methods
specific to values returned from this function.
data(feems)
cube <- feemscale(feemscatter(cube, rep(14, 4)), na.rm = TRUE)
factors <- feemparafac(cube, nfac = 3)
plot(factors, 'image')
plot(factors, 'line')
head(coef(factors, 'loadings'))
str(coef(factors, 'all'))
str(feemcube(factors)) # original cube is retained
plot(fitted(factors))
plot(resid(factors))
Run the code above in your browser using DataLab