Description Usage Arguments Details Value Author(s) See Also Examples
The standard definition for the inverse of a matrix fails if the matrix is not square or singular. However, one can generalize the inverse using singular value decomposition. Any rectangular real matrix M can be decomposed as
M = U D V',
where U and V are orthogonal, V' means V transposed, and
D is a diagonal matrix containing only the positive singular values
(as determined by tol
, see also fast.svd
).
The pseudoinverse, also known as Moore-Penrose or generalized inverse is then obtained as
iM = V D^(-1) U' .
1 | pseudoinverse(m, tol)
|
m |
matrix |
tol |
tolerance - singular values larger than
tol are considered non-zero (default value:
|
The pseudoinverse has the property that the sum of the squares of all
the entries in iM %*% M - I
, where I is an appropriate
identity matrix, is minimized. For non-singular matrices the
pseudoinverse is equivalent to the standard inverse.
A matrix (the pseudoinverse of m).
Korbinian Strimmer (https://strimmerlab.github.io).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # load corpcor library
library("corpcor")
# a singular matrix
m = rbind(
c(1,2),
c(1,2)
)
# not possible to invert exactly
try(solve(m))
# pseudoinverse
p = pseudoinverse(m)
p
# characteristics of the pseudoinverse
zapsmall( m %*% p %*% m ) == zapsmall( m )
zapsmall( p %*% m %*% p ) == zapsmall( p )
zapsmall( p %*% m ) == zapsmall( t(p %*% m ) )
zapsmall( m %*% p ) == zapsmall( t(m %*% p ) )
# example with an invertable matrix
m2 = rbind(
c(1,1),
c(1,0)
)
zapsmall( solve(m2) ) == zapsmall( pseudoinverse(m2) )
|
Error in solve.default(m) :
Lapack routine dgesv: system is exactly singular: U[2,2] = 0
[,1] [,2]
[1,] 0.1 0.1
[2,] 0.2 0.2
[,1] [,2]
[1,] TRUE TRUE
[2,] TRUE TRUE
[,1] [,2]
[1,] TRUE TRUE
[2,] TRUE TRUE
[,1] [,2]
[1,] TRUE TRUE
[2,] TRUE TRUE
[,1] [,2]
[1,] TRUE TRUE
[2,] TRUE TRUE
[,1] [,2]
[1,] TRUE TRUE
[2,] TRUE TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.