Calculates the Moore-Penrose generalized inverse of a matrix
X
.
USAGE:
ginv(X, tol = sqrt(.Machine$double.eps))
REQUIRED ARGUMENTS:
X
Matrix for which the Moore-Penrose inverse is required.
OPTIONAL ARGUMENTS:
tol
A relative tolerance to detect zero singular values.
VALUE:
A MP generalized inverse matrix for
X.
SEE ALSO:
,
,
EXAMPLES:
# The function is currently defined as
function(X, tol = sqrt(.Machine$double.eps))
{
## Generalized Inverse of a Matrix
dnx <- dimnames(X)
if(is.null(dnx)) dnx <- vector("list", 2)
s <- svd(X)
nz <- s$d > tol * s$d[1]
structure(
if(any(nz)) s$v[, nz] %*% (t(s$u[, nz])/s$d[nz]) else X,
dimnames = dnx[2:1])
}