slm                 package:SparseM                 R Documentation

_F_i_t _a _l_i_n_e_a_r _r_e_g_r_e_s_s_i_o_n _m_o_d_e_l _u_s_i_n_g _s_p_a_r_s_e _m_a_t_r_i_x _a_l_g_e_b_r_a

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

     This is a function to illustrate the use of sparse linear algebra
     to solve a linear least squares problem using Cholesky
     decomposition. The syntax and output attempt to emulate 'lm()' but
     may fail to do so fully satisfactorily.  Ideally, this would
     eventually become a method for 'lm'.  The main obstacle to this
     step is that it would be necessary to have a model.matrix function
     that returned an object in sparse csr form.  For the present, the
     objects represented in the formula must be in dense form.  If the
     user wishes to specify fitting with a design matrix that is
     already in sparse form, then the lower level function 'slm.fit()'
     should be used.

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

     slm(formula, data, weights, na.action, method = "csr", contrasts = NULL, ...)

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

 formula: a formula object, with the response on the left of a '~'
          operator, and the terms, separated by '+' operators, on the
          right.  As in 'lm()', the response variable in the formula
          can be matrix valued. 

    data: a data.frame in which to interpret the variables named in the
          formula, or in the subset and the weights argument. If this
          is missing, then the variables in the formula should be on
          the search list.  This may also be a single number to handle
          some special cases - see below for details. 

 weights: vector of observation weights; if supplied, the algorithm
          fits to minimize the sum of the weights multiplied into the
          absolute residuals. The length of weights must be the same as
          the number of observations.  The weights must be nonnegative
          and it is strongly recommended that they be strictly
          positive, since zero weights are ambiguous. 

na.action: a function to filter missing data. This is applied to the
          model.frame after any subset argument has been used. The
          default (with 'na.fail') is to create an error if any missing
           values are found.  A possible alternative is 'na.omit',
          which deletes observations that contain one or more missing
          values. 

  method: there is only one method based on Cholesky factorization

contrasts: a list giving contrasts for some or all of the factors
          default = 'NULL' appearing in the model formula. The elements
          of the list should have the same name as the variable and
          should be either a contrast matrix (specifically, any
          full-rank matrix with as many rows as there are levels in the
          factor), or else a function to compute such a matrix given
          the number of levels. 

     ...: additional arguments for the fitting routines 

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

     A list of class 'slm' consisting of: 

coefficients: estimated coefficients

    chol: cholesky object from fitting

residuals: residuals

  fitted: fitted values

   terms: terms

    call: call

     ...

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

     Roger Koenker

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

     Koenker, R and Ng, P. (2002).  SparseM:  A Sparse Matrix Package
     for R, 
      <URL: http://www.econ.uiuc.edu/~roger/research>

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

     'slm.methods' for methods 'summary', 'print', 'fitted',
     'residuals' and 'coef' associated with class 'slm', and 'slm.fit'
     for lower level fitting functions.  The latter functions are of
     special interest if you would like to pass a sparse form of the
     design matrix directly to the fitting process.

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

     data(lsq)
     X <- model.matrix(lsq) #extract the design matrix
     y <- model.response(lsq) # extract the rhs
     X1 <- as.matrix(X)
     slm.time <- unix.time(slm(y~X1-1) -> slm.o) # pretty fast
     lm.time <- unix.time(lm(y~X1-1) -> lm.o) # very slow
     cat("slm time =",slm.time,"\n")
     cat("slm Results: Reported Coefficients Truncated to 5  ","\n")
     sum.slm <- summary(slm.o)
     sum.slm$coef <- sum.slm$coef[1:5,]
     sum.slm
     cat("lm time =",lm.time,"\n")
     cat("lm Results: Reported Coefficients Truncated to 5  ","\n")
     sum.lm <- summary(lm.o)
     sum.lm$coef <- sum.lm$coef[1:5,]
     sum.lm

