KNex                 package:Matrix                 R Documentation

_K_o_e_n_k_e_r-_N_g _E_x_a_m_p_l_e _S_p_a_r_s_e _M_o_d_e_l _M_a_t_r_i_x _a_n_d _R_e_s_p_o_n_s_e _V_e_c_t_o_r

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

     A model matrix 'mm' and corresponding response vector 'y' used in
     an example by Koenker and Ng.  The matrix 'mm' is a sparse matrix
     with 1850 rows and 712 columns but only 8758 non-zero entries. It
     is a '"dgCMatrix"' object.  The vector 'y' is just 'numeric' of
     length 1850.

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

     data(KNex)

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

     Roger Koenker and Pin Ng (2003). SparseM: A sparse matrix package
     for R; _J. of Statistical Software_, *8* (6), <URL:
     http://www.jstatsoft.org/>

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

     data(KNex)
     class(KNex$mm)
       dim(KNex$mm)
     image(KNex$mm)
     str(KNex)

     system.time( # a fraction of a second
       sparse.sol <- with(KNex, solve(crossprod(mm), crossprod(mm, y))))

     head(round(sparse.sol,3))

     ## Compare with QR-based solution ("more accurate, but slightly slower"):
     system.time(
       sp.sol2 <- with(KNex, qr.coef(qr(mm), y) ))

     all.equal(sparse.sol, sp.sol2, tol = 1e-13) # TRUE

