l0ara: Fit a generalized linear model with an L0 penalty

View source: R/l0ara.R

l0araR Documentation

Fit a generalized linear model with an L0 penalty

Description

Fit a sparse generalized linear model by approximating the L0-penalized objective with an adaptive ridge algorithm.

Usage

l0ara(x, y, family, lam, standardize, maxit, eps)

Arguments

x

Design matrix. A numeric matrix is used as-is; other inputs must be coercible to a model matrix. Rows correspond to observations and columns to predictors.

y

Response vector. For accurate use, supply numeric outcomes for family = "gaussian", positive numeric outcomes for family = "gamma" and family = "inv.gaussian", binary outcomes coded as 0/1 for family = "logit", and non-negative counts for family = "poisson".

family

Model family.

lam

A single user-supplied penalty value. If you have a candidate sequence of values, use cv.l0ara() to choose lam.min and then refit with l0ara(). Setting lam = 2 mimics AIC-style model selection, and lam = log(n) mimics BIC-style model selection.

standardize

Logical flag indicating whether to standardize the columns of x before fitting. The original x is stored in the returned object.

maxit

Maximum number of iterations passed to the fitting routine.

eps

Convergence threshold. Default value is 1e-4.

Details

The objective function is

-(\log\mbox{-}\mathrm{likelihood}) + (\lambda / 2)|\beta|_0,

where |\beta|_0 is the number of non-zero elements of \beta. The adaptive ridge algorithm provides an efficient approximation to the corresponding L0-penalized generalized linear model.

Value

An object with S3 class "l0ara" containing:

beta

A vector of fitted coefficients.

df

Number of non-zero coefficients.

iter

Number of iterations used by the fitting routine.

lam

The supplied penalty value.

lambda

A copy of lam for compatibility with downstream methods.

family

The fitted model family.

x

The original design matrix supplied to the function.

y

The response vector supplied to the function.

Author(s)

Wenchuan Guo <wguo1017@gmail.com>, Shujie Ma <shujie.ma@ucr.edu>, Zhenqiu Liu <Zhenqiu.Liu@cshs.org>

See Also

cv.l0ara, predict.l0ara, coef.l0ara, plot.l0ara.

Examples

# Linear regression
# Generate design matrix and response variable
n <- 100
p <- 40
x <- matrix(rnorm(n*p), n, p)
beta <- c(1,0,2,3,rep(0,p-4))
noise <- rnorm(n)
y <- x%*%beta+noise
# fit sparse linear regression using BIC
res.gaussian <- l0ara(x, y, family="gaussian", log(n))

# predict for new observations
print(res.gaussian)
predict(res.gaussian, newx=matrix(rnorm(3,p),3,p))
coef(res.gaussian)

# Logistic regression
# Generate design matrix and response variable
n <- 100
p <- 40
x <- matrix(rnorm(n*p), n, p)
beta <- c(1,0,2,3,rep(0,p-4))
prob <- exp(x%*%beta)/(1+exp(x%*%beta))
y <- rbinom(n, rep(1, n), prob)
# fit sparse logistic regression
res.logit <- l0ara(x, y, family="logit", 0.7)

# predict for new observations
print(res.logit)
predict(res.logit, newx=matrix(rnorm(3,p),3,p))
coef(res.logit)

# Poisson regression
# Generate design matrix and response variable
n <- 100
p <- 40
x <- matrix(rnorm(n*p), n, p)
beta <- c(1,0,0.5,0.3,rep(0,p-4))
mu <- exp(x%*%beta)
y <- rpois(n, mu)
# fit sparse Poisson regression using AIC
res.pois <- l0ara(x, y, family="poisson", 2)

# predict for new observations
print(res.pois)
predict(res.pois, newx=matrix(rnorm(3,p),3,p))
coef(res.pois)

l0ara documentation built on April 27, 2026, 9:08 a.m.