This function attempts a standard SVD using base R's svd(). If that fails (typically due to ill-conditioning or non-convergence), it automatically falls back to a randomized SVD via the rsvd package.

ba_svd(
  x,
  nu = min(nrow(x), ncol(x)),
  nv = min(nrow(x), ncol(x)),
  dividebymax = FALSE,
  NA2Noise = TRUE
)

Arguments

x

A numeric matrix.

nu

Number of left singular vectors to compute. Default: min(nrow(x), ncol(x)).

nv

Number of right singular vectors to compute. Default: min(nrow(x), ncol(x)).

dividebymax

Logical. If TRUE, scale x by its max absolute value before SVD. Default: FALSE.

NA2Noise

boolean replaces NA values with small noise values

Value

A list with components u, d, and v, matching the structure of base R's svd() output.

Details

Optionally, the matrix can be scaled by its maximum absolute value to improve numerical stability before decomposition.

Examples

mat <- matrix(rnorm(100 * 50), 100, 50)
sv <- ba_svd(mat, nu = 10, nv = 0)