MPinv                  package:gnm                  R Documentation

_M_o_o_r_e-_P_e_n_r_o_s_e _P_s_e_u_d_o_i_n_v_e_r_s_e _o_f _a _R_e_a_l-_v_a_l_u_e_d _M_a_t_r_i_x

_D_e_s_c_r_i_p_t_i_o_n:

     Computes the Moore-Penrose generalized inverse, optionally using a
     method (appropriate for symmetric matrices only) which exploits
     the direct inversion of a diagonal submatrix if such exists.

_U_s_a_g_e:

     MPinv(mat, eliminate = numeric(0), onlyFirstCol = FALSE,
           onlyNonElim = FALSE, tolerance = 100*.Machine$double.eps)

_A_r_g_u_m_e_n_t_s:

     mat: A real matrix, which should be symmetric unless 'eliminate'
          has zero length. 

eliminate: Numeric.  A vector of indices identifying rows/columns which
          form a diagonal submatrix of 'mat'. 

onlyFirstCol: Logical.  If 'TRUE', return only the first column of the
          generalized inverse matrix; otherwise the whole matrix.

onlyNonElim: Logical.  If 'TRUE', return only rows/columns that are in
          the complement of the set specified in 'eliminate'.

tolerance: A positive scalar which determines the tolerance for
          detecting zeroes among the singular values. 

_D_e_t_a_i_l_s:

     Real-valuedness is not checked, and neither is symmetry or the
     diagonality of the submatrix when 'eliminate' is used.

     The purpose of the 'eliminate' argument is a substantial reduction
     of the computational burden when the number of `eliminated'
     rows/columns is large.

_V_a_l_u_e:

     A matrix, with an additional attribute named '"rank"' containing
     the numerically determined rank of the matrix.

_A_u_t_h_o_r(_s):

     David Firth

_R_e_f_e_r_e_n_c_e_s:

     Harville, D. A. (1997).  _Matrix Algebra from a Statistician's
     Perspective_.  New York: Springer.

_S_e_e _A_l_s_o:

     'ginv'

_E_x_a_m_p_l_e_s:

     A <- matrix(c(1, 1, 0,
                   1, 1, 0,
                   2, 3, 4), 3, 3)
     B <- MPinv(A)
     A %*% B %*% A - A  # essentially zero
     B %*% A %*% B - B  # essentially zero
     attr(B, "rank")    # here 2

     ## now a symmetric example with diagonal submatrix to `eliminate'
     A <- matrix(c(1, 0, 2,
                   0, 2, 3,
                   2, 3, 4), 3, 3)
     B <- MPinv(A, eliminate = 1:2)
     A %*% B %*% A - A  # essentially zero
     B %*% A %*% B - B  # essentially zero
     attr(B, "rank")        # here 3

     ## Not run: 
     ## demo that eliminate can give substantial speed gains
     A <- diag(rnorm(100))
     A <- cbind(A, matrix(rnorm(200), 100, 2))
     A <- rbind(A, cbind(t(A[, 101:102]), matrix(c(1, 2, 2, 1), 2, 2)))
     system.time(for (i in 1:1000) B <-  MPinv(A))
     ##  [1] 26.83 10.24 39.76  0.00  0.00
     system.time(for (i in 1:1000) B <-  MPinv(A, eliminate = 1:100))
     ##  [1] 3.49 1.37 5.04 0.00 0.00
     ## End(Not run)

