Learn R Programming

pcv (version 1.2.0)

flipSigns: Compute sign-flip diagonal matrix for direction correction of local loadings

Description

Compares column directions of two loading matrices and returns a diagonal matrix of +1/-1 signs. If the angle between corresponding columns exceeds 90 degrees, the sign is -1 (flip), otherwise +1 (keep). Input dot products are clamped to [-1, 1] before acos to avoid NaN from floating-point overshoot.

Usage

flipSigns(V1, V2)

Value

Diagonal matrix (ncol x ncol) with +1 or -1 on the diagonal

Arguments

V1

matrix with reference vectors as columns (e.g. global loadings)

V2

matrix with vectors to align as columns (e.g. local loadings)