ID EN
Miscellaneous

svd

R Base 3.6.2

Compute the singular-value decomposition of a rectangular matrix.

Syntax

R
svd(x, nu = min(n, p), nv = min(n, p), LINPACK = FALSE)<p></p><p>La.svd(x, nu = min(n, p), nv = min(n, p))</p>

Arguments

Parameter Description
x a numeric or complex matrix whose SVD decomposition is to be computed. Logical matrices are coerced to numeric.
nu the number of left singular vectors to be computed. This must between 0 and n = nrow(x).
nv the number of right singular vectors to be computed. This must be between 0 and p = ncol(x).
LINPACK logical. Defunct and ignored.

Return Value

The SVD decomposition of the matrix as computed by LAPACK, $$ \bold{X = U D V'},$$ where \(\bold{U}\) and \(\bold{V}\) are orthogonal, \(\bold{V'}\) means V transposed (and conjugated for complex input), and \(\bold{D}\) is a diagonal matrix with the (non-negative) singular values \(D_{ii}\) in decreasing order. Equivalently, \(\bold{D = U' X V}\), which is verified in the examples. The returned value is a list with components da vector containing the singular values of x, of length min(n, p), s

Details

The singular value decomposition plays an important role in many statistical techniques. svd and La.svd provide two interfaces which differ in their return values. Computing the singular vectors is the slow part for large matrices. The computation will be more efficient if both nu <= min(n, p) and nv <= min(n, p), and even more so if both are zero. Unsuccessful results from the underlying LAPACK code will result in an error giving a positive error code (most often 1): these can only be interpreted by detailed study of the FORTRAN code but mean that the algorithm failed to converge.

Examples

Example
R
# NOT RUN {
hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }
X <- hilbert(9)[, 1:6]
(s <- svd(X))
D <- diag(s$d)
s$u %*% D %*% t(s$v) #  X = U D V'
t(s$u) %*% X %*% s$v #  D = U' X V
# }

See Also

eigen qr.