align: Align Loadings of Principal Components

View source: R/SRPCAMS_helpers.R

alignR Documentation

Align Loadings of Principal Components

Description

Aligns loadings per neighborhood for better visualization and comparison. Different options are available.

Usage

align(PC, type = "largest", vec = NULL)

Arguments

PC

Array of loadings of size p x k x N as returned by msPCA$PC.

type

Character string specifying the sign adjustment method. One of:

"largest" Sets the sign so that the largest (by absolute value) loading is positive, per neighborhood and component.
"maxvar" Makes the variable with the highest absolute value positive, per neighborhood and component.
"nonzero" Makes the loading with the largest distance from zero over neighborhoods positive, per neighborhood and component.
"scalar" Adjusts signs so that the scalar product with vec is positive, per neighborhood and component. vec can be a p-dimensional vector used across all components and neighborhoods, a (p x k) matrix for individual vectors for components, or a (pN x k) matrix with individual vectors for each neighborhood and component
"mean" Like "scalar", but vec is the mean of loadings across neighborhoods for each components.
"none" No sign adjustment; returns the raw PC.
vec

NULL or vector containing vectors for type "scalar". If vec is of dimension p × k, the same vec is used for all neighborhoods.

Value

Returns an array of loadings of size p times k times N.

Examples

set.seed(1)

# Note, that in this example the vectors are not feasible loadings.
COVS = list("a"= matrix(runif(16, -1, 1), 4), "b" = matrix(runif(16, -1, 1), 4))
COVS = lapply(COVS, function(x) x %*% t(x))

pca = msPCA(eta = 1, gamma = 0.5, COVS = COVS, k = 2)
x = pca$PC

align(PC = x, type = "largest")
align(PC = x, type = "maxvar")
align(PC = x, type = "mean")
align(PC = x, type = "nonzero")
align(PC = x, type = "scalar", vec = c(1,1,1,1))

ssMRCD documentation built on Nov. 5, 2025, 7:44 p.m.