blockpls: Block dimension reduction by PCA or PLS

View source: R/blockpls.R

blockplsR Documentation

Block dimension reduction by PCA or PLS

Description

Function blockpls implements a dimension reduction of pre-selected blocks of variables (= set of columns) of a reference (= training) matrix and eventually a new (= test) matrix, by PCA (default) or PLS. The block reduction consists in calculating latent variables (= scores) independently for each block.

The scores calculated for each block for the reference matrix are concatenated into a new output matrix. The same is done for the eventual test scores.

The function allows giving a priori weights to the rows of the reference matrix in the calculations (argument weights to specify within the optional arguments "...").

Usage


blockpls(Xr, Yr = NULL, Xu = NULL, blocks, colblocks = NULL, ncomp, ...)

Arguments

Xr

A n x p matrix or data frame of reference (= training) observations.

Yr

A n x q matrix or data frame, or a vector of length n, of reference (= training) responses. If NULL (default), the reduction methods is PCA; in the other case, it is PLS.

Xu

A m x p matrix or data frame of new (= test) observations, which receives the same block-scaling as Xr (Xu is not used in the calculation of the block score spaces). Default to NULL.

blocks

A list of same length as the number of blocks. Each component of the list gives the column numbers in Xr defining the given block. The same blocks are used for Xu.

colblocks

Alternative to using argument blocks. A numeric vector of length p giving the index of the block for each of the columns of Xr (the same vector is used for Xu). Default to NULL (argument blocks is used instead).

ncomp

A list of same length as the number of blocks defining the number of scores to calculate for each block, or a single number. In this last case, the same number of scores is used for all the blocks.

...

Other arguments to pass in functions pls or pca.

Value

Tr

A matrix with the scores calculated from Xr and concatenated by block.

Tu

A matrix with the scores calculated from Xu and then concatenated by block. NULL if Xu = NULL.

blocks

A list of column numbers defining the blocks in the output matrices Tr and Tu.

Examples


n <- 5 ; p <- 10
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
colnames(X) <- paste("Var", 1:p, sep = "")
Y <- matrix(rnorm(n * 2, mean = 10), ncol = 2, byrow = TRUE)
set.seed(NULL)
X
Y

blocks <- list(1:3, 4:6, 7:9)
blocks

res <- blockpls(X[1:3, ], Xu = X[4:5, ], blocks = blocks, ncomp = 2) 
#res <- blockpls(X[1:3, ], Xu = X[4:5, ], colblocks = c(rep(1, 3), rep(2, 3), rep(3, 3)), ncomp = 2) 
#res <- blockpls(X[1:3, ], Y[1:3, ], X[4:5, ], blocks = blocks, ncomp = c(2, 1, 1)) 
res


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.