Learn R Programming

Matrix (version 0.3-19)

SVD: Singular Value Decomposition of a Matrix

Description

Compute the singular-value decomposition of a rectangular matrix.

Usage

SVD(x, nu = min(n,p), nv = min(n,p))

Arguments

x
a matrix whose SVD decomposition is to be computed.
nu
the number of left eigenvectors to be computed. This must be one of 0, nrow(x) and ncol(x).
nv
the number of right eigenvectors to be computed. This must be one of 0, and ncol(x).

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 $\bold{D}$ is a diagonal matrix with the singular values $D_{ii}$. Equivalently, $\bold{D = U' X V}$, which is verified in the examples, below.

    The components in the returned value correspond directly to the values returned by DGESVD.

  • da vector containing the singular values of x.
  • ua matrix whose columns contain the left eigenvectors of x.
  • vta matrix whose rows contain the right eigenvectors of x. That is, the vt component is the transpose of $\bold{V}$ in the above decomposition. This is different from the LINPACK result which returns $\bold{V}$.

Details

SVD provides an interface to the Lapack routine DGESVD. The singular value decomposition plays an important role in many statistical techniques.

See Also

svd, eigen, qr.

Examples

Run this code
str(X <- hilbert(9)[,1:6])
str(s <- SVD(X))
Eps <- 100 * .Machine$double.eps

D <- diag(s$d)
stopifnot(abs(X - s$u %*% D %*% s$vt) < Eps)#  X = U D V'
stopifnot(abs(D - t(s$u) %*% X %*% t(s$vt)) < Eps)#  D = U' X V

X <- cbind(1, 1:7)
str(s <- SVD(X)); D <- diag(s$d)
stopifnot(abs(X - s$u %*% D %*% s$vt) < Eps)#  X = U D V'
stopifnot(abs(D - t(s$u) %*% X %*% t(s$vt)) < Eps)#  D = U' X V

Run the code above in your browser using DataLab