l0ara

CRAN RStudio mirror downloads

Overview

l0ara fits sparse generalized linear models using an adaptive ridge approximation to an L0 penalty.

Installation

Install the package from CRAN with:

install.packages("l0ara")

Basic usage

Fit a sparse Gaussian model:

library(l0ara)

n <- 100
p <- 40
x <- matrix(rnorm(n * p), n, p)
beta <- c(1, 0, 2, 3, rep(0, p - 4))
y <- x %*% beta + rnorm(n)

fit <- l0ara(x, y, family = "gaussian", lam = log(n))
print(fit)
coef(fit)

Select the penalty by cross-validation:

lam <- c(0.1, 0.3, 0.5)
cv_fit <- cv.l0ara(x, y, family = "gaussian", lam = lam, measure = "mse")

print(cv_fit)
coef(cv_fit)
plot(cv_fit)