Generalized Inverse in R
Most of the time you don't really want the inverse of a matrix, because the end result can be ruined by rounding errors by the time you're done.
It's more typical to create the LU decomposition using partial pivoting and scaling. Use it to perform forward/back substitution on right-hand-side vector to get the solution. This is especially helpful if you have multiple RHS vectors, because you can apply it repeatedly.
You need the Matrix package to do this.
MYaseen208
Updated on June 14, 2022Comments
-
MYaseen208 almost 2 years
I can use
ginv
function fromMASS
library to get Moore-Penrose Generalisied Inverse of a matrix.m <- matrix(1:9, 3, 3) library(MASS) ginv(m)
In SAS we do have more than one function to get a generalized inverse of a matrix. SVD can be used to find the generalized inverse but again this is a Moore-Penrose. I wonder if there any function in R to get a generalized inverse of a matrix (which is not unique) other than Moore-Penrose Generalisied Inverse. Thanks in advance for your help and time.
Edit
A generalized inverse of a matrix A is defined as any matrix G that satisfies the equation AGA = A.
This G is not a Moore-Penrose Generalisied Inverse so it is not unique.
-
Iterator over 12 yearsWhat other pseudo inverses would you like? Could you be more precise what you'd like to mimic from SAS?
-
Ben Bolker over 12 yearsTo quote an often-seen signature on the R help list: "what is the problem you are trying to solve?"
-
-
MYaseen208 over 12 yearsThanks for your comment. Would you like to provide an example. Thanks
-
Stéphane Laurent over 2 yearsBe careful with
pracma::pinv
, it returns a wrong result for matrices with complex entries. I sent a mail to the author today to tell him. The pseudo-inverse is also available in the EigenR package.