consensuspca: consensus PCA

View source: R/consensuspca.R

consensuspcaR Documentation

consensus PCA

Description

Algorithms fitting a consensus PCA of a list of matrices Xlist. A chosen PCA algorithm is applied on the X-matrix obtained after variable scaling, blockscaling, block concatenation.

Auxiliary functions

transform Calculates the principal components for any new matrix X from the model.

summary returns summary information for the model.

Usage


consensuspca(Xlist, blockscaling = TRUE, weights = NULL, nlv, 
      Xscaling = c("none", "pareto", "sd")[1], 
      algo = c("svd","eigen","eigenk","nipals","nipalsna","sph")[1], 
      gs = TRUE, tol = .Machine$double.eps^0.5, maxit = 200)

## S3 method for class 'Consensuspca'
transform(object, X, ..., nlv = NULL) 

## S3 method for class 'Consensuspca'
summary(object, X, ...) 

Arguments

Xlist

For the main function: list of training X-data (nrows).

X

For the auxiliary functions: list of new X-data, with the same variables than the training X-data.

blockscaling

logical. If TRUE, the scaling factor (computed on the training) is the "norm" of the block, i.e. the square root of the sum of the variances of each column of the block.

weights

excepted for "nipalsna". Weights (n, 1) to apply to the training observations. Internally, weights are "normalized" to sum to 1. Default to NULL (weights are set to 1 / n).

nlv

For the main functions: The number(s) of PCs to calculate. — For the auxiliary functions: The number(s) of PCs to consider.

Xscaling

vector (of length Xlist) of variable scaling for each datablock, among "none" (mean-centering only), "pareto" (mean-centering and pareto scaling), "sd" (mean-centering and unit variance scaling). If "pareto" or "sd", uncorrected standard deviation is used.

algo

For consensuspca, the algorithm for the PCA among : "svd" (SVD factorization of D^(1/2) * X, using function svd), "eigen" (Eigen factorization of X' * D * X, using function eigen), "eigenk" (Eigen factorization of D^(1/2) * X * X' D^(1/2), using function eigen), "nipals" (Eigen factorization of X' * D * X using NIPALS), "nipalsna" (Eigen factorization of X' * D * X using NIPALS allowing missing data in X), "sph" (Robust spherical PCA)

object

For the auxiliary functions: A fitted model, output of a call to the main functions.

...

For the auxiliary functions: Optional arguments. Not used.

Specific for the NIPALS algorithm

gs

Logical indicating if a Gram-Schmidt orthogonalization is implemented or not (default to TRUE).

tol

Tolerance for testing convergence of the NIPALS iterations for each PC.

maxit

Maximum number of NIPALS iterations for each PC.

Value

For consensuspca:

T

The X-score matrix (n, nlv).

P

The X-loadings matrix (p, nlv).

sv

The singular values (min(n, p), 1) except for NIPALS = (nlv, 1).

eig

The eigenvalues (= sv^2) (min(n, p), 1) except for NIPALS = (nlv, 1).

xmeans

The list of centering vectors of Xlist.

xscales

The list of Xlist variable standard deviations.

weights

Weights applied to the training observations.

blockscaling

block scaling.

Xnorms

"norm" of each block, i.e. the square root of the sum of the variances of each column of each block, computed on the training, and used as scaling factor

.

niter

Numbers of iterations of the NIPALS.

conv

Logical indicating if the NIPALS converged before reaching the maximal number of iterations.

For transform.Consensuspca: X-scores matrix for new Xlist-data.

For summary.Consensuspca:

explvarx

matrix of explained variances.

contr_ind

observation contributions.

contr_var

variable contributions.

coord_var

variable coordinates.

cor_circle

variable coordinates on the correlation circle.

References

Mangamana, E.T., Cariou, V., Vigneau, E., Glele Kakai, R.L., Qannari, E.M., 2019. Unsupervised multiblock data analysis: A unified approach and extensions. Chemometrics and Intelligent Laboratory Systems 194, 103856. https://doi.org/10.1016/j.chemolab.2019.103856

Westerhuis, J.A., Kourti, T., MacGregor, J.F., 1998. Analysis of multiblock and hierarchical PCA and PLS models. Journal of Chemometrics 12, 301–321. https://doi.org/10.1002/(SICI)1099-128X(199809/10)12:5<301::AID-CEM515>3.0.CO;2-S

Examples


n <- 10 ; p <- 10
Xtrain <- matrix(rnorm(n * p), ncol = p)
ytrain <- rnorm(n)

m <- 2
Xtest <- matrix(rnorm(m * p), ncol = p)

colnames(Xtrain) <- colnames(Xtest) <- paste("v", 1:p, sep = "")

Xtrain
Xtest

blocks <- list(1:2, 4, 6:8)
X1 <- mblocks(Xtrain, blocks = blocks)
X2 <- mblocks(Xtest, blocks = blocks)

nlv <- 3
fm <- consensuspca(Xlist = X1, Xscaling = c("sd","none","none"), 
blockscaling = TRUE, weights = NULL, nlv = nlv)

summary(fm, X1)
transform(fm, X2)


rchemo documentation built on June 30, 2026, 5:10 p.m.