Language Reference


GINV Function

GINV (matrix);

The GINV function computes the Moore-Penrose generalized inverse of matrix. This inverse, known as the four-condition inverse, has these properties:

If $\mb{G} = \mbox{GINV}(\mb{A})$ then

\[  \mb{AGA} = \mb{A} ~ ~ ~  \mb{GAG}= \mb{G} ~ ~ ~  (\mb{AG})^{\prime } = \mb{AG} ~ ~ ~  (\mb{GA})^{\prime } = \mb{GA} ~   \]

The generalized inverse is also known as the pseudoinverse, usually denoted by $\mb{A}^{-}$. It is computed by using the singular value decomposition (Wilkinson and Reinsch, 1971).

See Rao and Mitra (1971) for a discussion of properties of this function.

As an example, consider the following model:

\[  \mb{Y}= \mb{X} \bbeta + \bepsilon  \]

Least squares regression for this model can be performed by using the quantity ginv(x)*y as the estimate of $\bbeta $. This solution has minimum $\mb{b}^{\prime }\mb{b}$ among all solutions that minimize $\bepsilon ^{\prime }\bepsilon $, where $\bepsilon = \mb{Y} - \mb{Xb}$.

Projection matrices can be formed by specifying GINV$(\mb{X})*\mb{X}$ (row space) or $\mb{X}*$GINV$(\mb{X})$ (column space).

The following program demonstrates some common uses of the GINV function:

A = {1 0 1 0 0,
     1 0 0 1 0,
     1 0 0 0 1,
     0 1 1 0 0,
     0 1 0 1 0,
     0 1 0 0 1 };

/* find generalized inverse */
Ainv = ginv(A);

/* find LS solution: min  |Ax-b|^2 */
b = { 3, 2, 4, 2, 1, 3 };
x = Ainv*b;

/* form projection matrix onto row space.
   Note P = P` and P*P = P */
P = Ainv*A;

/* find numerical rank of A */
rankA = round(trace(P));

reset fuzz;
print Ainv, rankA, x, P;

Figure 24.146: Common Uses of the Generized Inverse

Ainv
0.2666667 0.2666667 0.2666667 -0.066667 -0.066667 -0.066667
-0.066667 -0.066667 -0.066667 0.2666667 0.2666667 0.2666667
0.4 -0.1 -0.1 0.4 -0.1 -0.1
-0.1 0.4 -0.1 -0.1 0.4 -0.1
-0.1 -0.1 0.4 -0.1 -0.1 0.4

rankA
4

x
2
1
1
0
2

P
0.8 -0.2 0.2 0.2 0.2
-0.2 0.8 0.2 0.2 0.2
0.2 0.2 0.8 -0.2 -0.2
0.2 0.2 -0.2 0.8 -0.2
0.2 0.2 -0.2 -0.2 0.8



If $\mb{A}$ is an $n\times m$ matrix, then, in addition to the memory allocated for the return matrix, the GINV function temporarily allocates an $n^2 + nm$ array for performing its computation.