

qr {base}                                    R Documentation

_T_h_e _Q_R _D_e_c_o_m_p_o_s_i_t_i_o_n _o_f _a _M_a_t_r_i_x

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

     `qr' computes the QR decomposition of a matrix.  It
     provides an interface to the techniques used in the
     LINPACK routine DQRDC.

_U_s_a_g_e_:

     qr(x, tol=1e-07)
     qr.coef(qr, y)
     qr.qy(qr, y)
     qr.qty(qr, y)
     qr.resid(qr, y)
     qr.fitted(qr, y, k = qr$rank)
     qr.solve(a, b, tol = 1e-7)

     is.qr(x)
     as.qr(x)

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

       x: a matrix whose QR decomposition is to be computed.

     tol: the tolerance for detecting linear dependencies in
          the columns of `x'.

      qr: a QR decomposition of the type computed by `qr'.

    y, b: a vector or matrix of right-hand sides of equa-
          tions.

       a: A matrix or QR decomposition.

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

     The QR decomposition plays an important role in many
     statistical techniques.  In particular it can be used
     to solve the equation Ax = b for given matrix A, and
     vector b.  It is useful for computing regression coef-
     ficients and in applying the Newton-Raphson algorithm.

     The functions `qr.coef', `qr.resid', and `qr.fitted'
     return the coefficients, residuals and fitted values
     obtained when fitting `y' to the matrix with QR decom-
     position `qr'.  `qr.qy' and `qr.qty' return `Q %*% y'
     and `t(Q) %*% y', where `Q' is the Q matrix.

     `qr.solve' solves systems of equations via the QR
     decomposition.

     `is.qr' returns `TRUE' if `x' is a list with a compo-
     nent named `qr' and `FALSE' otherwise.

     It is not possible to coerce objects to mode `"qr"'.
     Objects either are QR decompositions or they are not.

_V_a_l_u_e_:

     The QR decomposition of the matrix as computed by LIN-
     PACK.  The components in the returned value correspond
     directly to the values returned by DQRDC.

      qr: a matrix with the same dimensions as `x'.  The
          upper triangle contains the R of the decomposition
          and the lower triangle contains information on the
          Q of the decomposition (stored in compact form).

   qraux: a vector of length `ncol(x)' which contains addi-
          tional information on Q.

    rank: the rank of `x' as computed by the decomposition.

   pivot: information on the pivoting strategy used during
          the decomposition.

_N_o_t_e_:

     To compute the determinant of a matrix (do you really
     need it?), the QR decomposition is much more efficient
     than using Eigen values (`eigen').  See `det2' in the
     examples below.

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

     Dongarra, J. J., J. R. Bunch, C. B. Moler and G. W.
     Stewart (1978).  LINPACK Users Guide.  Philadelphia,
     PA:  SIAM Publications.

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

     `qr.Q',  `qr.R',  `qr.X' for reconstruction of the
     matrices.  `solve.qr',  `lsfit', `eigen', `svd'.

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

     ## The determinant of a matrix  -- if you really must have it
     det2 <- function(x) prod(diag(qr(x)$qr))*(-1)^(ncol(x)-1)
     det2(print(cbind(1,1:3,c(2,0,1))))

     hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }
     h9 <- hilbert(9); h9
     qr(h9)$rank           #--> only 7
     qrh9 <- qr(h9, tol = 1e-10)
     qrh9$rank             #--> 9
     ##-- Solve linear equation system  H %*% x = y :
     y <- 1:9/10
     x <- qr.solve(h9, y, tol = 1e-10) # or equivalently :
     x <- qr.coef(qrh9, y) #-- is == but much better than
                           #-- solve(h9) %*% y
     h9 %*% x              # = y

