Language Reference

GINV Function

computes the generalized inverse

GINV( matrix)

where matrix is a numeric matrix or literal.

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

If g = {ginv}(a) then
{aga} = a    {gag}= g    ({ag})^' = {ag}    ({ga})^' = {ga}
The generalized inverse is also known as the pseudoinverse, usually denoted by 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.

Consider the following model:
y= {x \beta} +{\epsilon}
Least squares regression for this model can be performed by using the following statement as the estimate of {\beta}:
  
    b=ginv(x)*y;
 
This solution has minimum b^'b among all solutions minimizing {\epsilon}^'{\epsilon}, where {\epsilon} = y - {xb}.

Projection matrices can be formed by specifying GINV(x)*x (row space) or x*GINV(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; 
  
  
                                   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 a is an n x 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.

Previous Page | Next Page | Top of Page