blockscal: Block autoscaling

View source: R/blockscal.R

blockscalR Documentation

Block autoscaling

Description

Function blockscal autoscales the blocks (i.e. sets of columns) of a reference (= training) matrix and eventually a new (= test) matrix, and concatenates the scaled blocks into two new output matrices.

Each block of the reference matrix is scaled by its "norm", i.e. the square root of the sum of the variances of each column of the block. The blocks of the test matrix are scaled by the norms of the blocks of the reference matrix.

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 "...").

Outputs Xr and Xu of blockscal can be used as inputs of functions such as pls (= MB-PLS), plsr (= MB-PLSR), etc.

Usage


blockscal(Xr, Xu = NULL, blocks, colblocks = NULL, weights = NULL)

Arguments

Xr

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

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 dispersion measure). 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).

weights

A vector of length n defining a priori weights to apply to the training observations for the column variance calculation. Internally, weights are "normalized" to sum to 1. Default to NULL (weights are set to 1 / n).

Value

Xr

A matrix with the concatenated scaled blocks from Xr.

Xu

A matrix with the concatenated scaled blocks from Xu. NULL if Xu = NULL.

blocks

A list of column numbers defining the blocks in the output matrices Xr and Xu.

Examples


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

blocks <- list(1:2, 4, 6:8)
blocks

res <- blockscal(X[1:3, ], X[4:5, ], blocks)
res

blockscal(res$Xr, blocks = res$blocks)

blockscal(X[1:3, ], X[4:5, ], colblocks = c(rep(1, 3), rep(2, 7)))


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