This function performs SVD on a matrix using the built-in svd function in R. The matrix will be divided by its maximum value before computing the SVD for the purposes of numerical stability (optional). If svd fails, it automatically switches to random svd from the rsvd package. svd may fail to converge when the matrix condition number is high; this can be checked with the kappa function.

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

Arguments

x

Matrix to perform SVD on

nu

Number of left singular vectors to return (default: min(nrow(x), ncol(x)))

nv

Number of right singular vectors to return (default: min(nrow(x), ncol(x)))

dividebymax

boolean

Value

A list containing the SVD decomposition of x

Examples

avgU <- matrix(rnorm(100*50), nrow = 100, ncol = 50)
nc <- 10
u <- ba_svd( avgU, nu = nc, nv = 0)$u