getNcomp: Get optimal number of components

View source: R/getNcomp.R

getNcompR Documentation

Get optimal number of components

Description

Compute the average silhouette coefficient for a given set of components on a mixOmics result. Foreach given ncomp, the mixOmics method is performed with the sames arguments and the given 'ncomp'. Longitudinal clustering is performed and average silhouette coefficient is computed.

Usage

getNcomp(object, max.ncomp = NULL, X, Y = NULL, indY = NULL, ...)

Arguments

object

A mixOmics object of the class 'pca', 'spca', 'mixo_pls', 'mixo_spls', 'block.pls', 'block.spls'

max.ncomp

integer, maximum number of component to include. If no argument is given, 'max.ncomp=object$ncomp'

X

a numeric matrix/data.frame or a list of data.frame for block.pls

Y

(only for pls, optional for block.spls) a numeric matrix, with the same nrow as X

indY

(optional and only for block.pls, if Y is not provided), an integer which indicates the position of the matrix response in the list X

...

Other arguments to be passed to methods (pca, pls, block.pls)

Value

getNcomp returns a list with class "ncomp.tune.silhouette" containing the following components:

ncomp

a vector containing the tested ncomp

silhouette

a vector containing the average silhouette coefficient by ncomp

dmatrix

the distance matrix used to compute silhouette coefficient

See Also

getCluster, silhouette, pca, pls, block.pls

Examples

# random input data
demo <- suppressWarnings(get_demo_cluster())

# pca
pca.res <- mixOmics::pca(X=demo$X, ncomp = 5)
res.ncomp <- getNcomp(pca.res, max.ncomp = 4, X = demo$X)
plot(res.ncomp)

# pls
pls.res <- mixOmics::pls(X=demo$X, Y=demo$Y)
res.ncomp <- getNcomp(pls.res, max.ncomp = 4, X = demo$X, Y=demo$Y)
plot(res.ncomp)

# block.pls
block.pls.res <- suppressWarnings(mixOmics::block.pls(X=list(X=demo$X, Z=demo$Z), Y=demo$Y))
res.ncomp <- suppressWarnings(getNcomp(block.pls.res, max.ncomp = 4,
                                       X=list(X=demo$X, Z=demo$Z), Y=demo$Y))
plot(res.ncomp)


abodein/timeOmics_BioC documentation built on April 1, 2022, 6:59 a.m.