Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generalized Inverse in R

Tags:

r

matrix

sas

I can use ginv function from MASS 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.

like image 253
MYaseen208 Avatar asked Oct 30 '25 11:10

MYaseen208


1 Answers

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.

like image 111
duffymo Avatar answered Nov 02 '25 00:11

duffymo