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

