rankMatrix              package:Matrix              R Documentation

_R_a_n_k _o_f _a _M_a_t_r_i_x

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

     Compute the rank of matrix, a well-defined functional in theory,
     somewhat ambigous in practice.  We provide several methods, the
     default corresponding to Matlab's definition.

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

     rankMatrix(x, tol = NULL,
                method = c("tolNorm2", "qrLINPACK", "useGrad", "maybeGrad"),
                sval = svd(x, 0, 0)$d)

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

       x: numeric matrix, of dimension n x m, say.

     tol: nonnegative number specifying a tolerance for practically
          zero with specific meaning depending on 'method'; by
          default, 'max(dim(x)) * .Machine$double.eps * abs(max(sval))'
          is according to Matlab's default (for its only 'method'
          "tolNorm2").

  method: a character string specifying the computational method, can
          be abbreviated:

          _t_o_l_N_o_r_m_2 the number of singular values '>= tol';

          _q_r_L_I_N_P_A_C_K = 'qr(x, tol, LAPACK=FALSE)$rank'; this used to be
               _the_ recommended way to compute a matrix rank for a
               while in the past.  For this method, 'sval' are not used
               (nor computed).

          _u_s_e_G_r_a_d considering the gradient of the (decreasing)
               singular values, the index of the _smallest_ gap.

          _m_a_y_b_e_G_r_a_d choosing method '"useGrad"' only when that seems
               _reasonable_; otherwise using '"tolNorm2"'.

    sval: numeric vector of non-increasing singular values of 'x';
          typically unspecified and computed from 'x'.

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

     positive integer in '1:min(dim(x))', with attributes detailing the
     method used.

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

     Martin Maechler; for the "*Grad" methods, building on suggestions
     by Ravi Varadhan.

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

     'qr', 'svd'.

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

     rankMatrix(cbind(1, 0, 1:3)) # 2

     (meths <- eval(formals(rankMatrix)$method))

     ## a "border" case:
     H12 <- Hilbert(12)
     rankMatrix(H12, tol = 1e-20) # 12;  but  11  with default method & tol.
     sapply(meths, function(.m.) rankMatrix(H12, method = .m.))
     ## tolNorm2 qrLINPACK   useGrad maybeGrad
     ##       11        12        11        11

