knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)
library(sparseR)

sparseR: Sift smartly through interactions & polynomials with ranked sparsity

codecov R-CMD-check CRAN status

What is ranked sparsity?

The ranked sparsity methods such as the sparsity-ranked lasso (SRL) have been developed for model selection and estimation in the presence of interactions and polynomials (Peterson & Cavanaugh 2022)[https://doi.org/10.1007/s10182-021-00431-7]. The main idea is that an algorithm should be more skeptical of higher-order polynomials and interactions a priori compared to main effects, by a predetermined amount.

Package overview

The sparseR package has many features designed to streamline sifting through the high-dimensional space of interaction terms and polynomials, including functions for variable pre-processing, variable selection, post-selection inference, and post-fit model visualization under ranked sparsity. The package implements ranked-sparsity-based versions of the lasso, elastic net, MCP, and SCAD. We also provide a (preliminary) version of an sparsity-ranked extension to Bayesian Information Criterion (and corresponding stepwise approaches).

Installation

## Via GitHub: 
# install.packages("devtools")
devtools::install_github("petersonR/sparseR")

# or via CRAN
install.packages("sparseR")

Example

library(sparseR)
data(iris)
srl <- sparseR(Sepal.Width ~ ., data = iris, k = 1, poly = 2, seed = 1)
srl

par(mfrow = c(2,1), mar = c(4, 4, 3, 1))
plot(srl, plot_type = "both")

summary(srl, at = "cv1se")
effect_plot(srl, "Petal.Width", by = "Species", at = "cv1se", legend_location = "topright")

For more examples and a closer look at how to use this package, check out the package website.

Many thanks to the authors and maintainers of ncvreg and recipes.



petersonR/sparseR documentation built on April 17, 2025, 11:41 p.m.