# Using the sprintr package In sprintr: Sparse Reluctant Interaction Modeling

cb <- cbind(mod$idx, estimate) cb[cb[, 3] != 0, ]  ## Using cross-validation with cv.sprinter The function cv.sprinter() performs cross-validation to select the value of lasso tuning parameter lambda used in Step 3, while holding the value of num_keep fixed. mod_cv <- cv.sprinter(x = x, y = y, square = FALSE, nlam = 100, lam_min_ratio = 0.01)  The output of cv.sprinter is a S3 object. The most intersting information is mod_cv$compact, which is a matrix of three columns. The first two columns show the index pairs of all variables finally selected by the lasso in Step 3, and the last column is the coefficient estimate corresponding to that selected variable.

mod_cv\$compact


We see (from the first two rows and the last two rows) that the fit selected by cross-validation includes all the four important variables in the model, with relatively accurate estimates of their coefficients.

Finally, there is a predict function for the S3 object returned by cv.sprinter that computes the prediction for a new data matrix of main effects:

newdata <- matrix(rnorm(20 * p), nrow = 20, ncol = p)
pred <- predict(mod_cv, newdata = newdata)


## Try the sprintr package in your browser

Any scripts or data that you put into this service are public.

sprintr documentation built on Aug. 24, 2019, 5:03 p.m.