Welcome to ClientVPS Mirrors

Help for package l0ara
Type: Package
Title: Sparse Generalized Linear Model with L0 Approximation for Feature Selection
Version: 0.1.7
Date: 2026-04-25
Description: Fits sparse generalized linear models using an adaptive ridge approximation to an L0 penalty. Supported model families include Gaussian, logistic, Poisson, gamma, and inverse Gaussian regression. The package also provides cross-validation for selecting the penalty parameter.
License: GPL-2
Imports: Rcpp (≥ 0.12.6)
LinkingTo: Rcpp, RcppArmadillo
Encoding: UTF-8
RoxygenNote: 7.3.3
NeedsCompilation: yes
Packaged: 2026-04-26 01:59:52 UTC; wguo
Author: Wenchuan Guo [aut, cre], Shujie Ma [aut], Zhenqiu Liu [aut]
Maintainer: Wenchuan Guo <wguo1017@gmail.com>
Repository: CRAN
Date/Publication: 2026-04-27 07:20:02 UTC

Extract coefficients from a "cv.l0ara" object

Description

Return coefficients from the model refit at the selected lam.min.

Usage

## S3 method for class 'cv.l0ara'
coef(object, ...)

Arguments

object

Fitted "cv.l0ara" object.

...

Not used argument.

Details

If object$fit.min is missing, the model is refit on the full data using lam.min.

Value

A named numeric vector of fitted coefficients.

Author(s)

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

See Also

predict.l0ara, l0ara, cv.l0ara.


Extract coefficients from a "l0ara" object

Description

Return the fitted coefficient vector.

Usage

## S3 method for class 'l0ara'
coef(object, ...)

Arguments

object

Fitted "l0ara" object.

...

Not used argument.

Value

A named numeric vector of fitted coefficients.

Author(s)

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

See Also

predict.l0ara, l0ara.


Cross-validation for l0ara

Description

Perform k-fold cross-validation over a supplied sequence of penalty values and return the value selected by the chosen measure.

Usage

cv.l0ara(x, y, family, lam, measure, nfolds, maxit, eps, seed)

Arguments

x

Input matrix as in l0ara.

y

Response variable as in l0ara.

family

Model family as in l0ara.

lam

A user-supplied sequence of candidate penalty values. At least two values are required.

measure

Criterion used to compare folds. Use "mse" or "mae" for any supported family. Use "class" or "auc" only with family = "logit".

nfolds

Number of folds. Default value is 10. Smallest value is 3.

maxit

Maximum number of iterations passed to each call to l0ara().

eps

Convergence threshold. Default value is 1e-4.

seed

Optional random seed used to generate the fold assignments.

Details

For each fold, the function fits one model per value in lam, evaluates the requested measure on the held-out data, and then averages the results across folds. For measure = "auc", the selected value is the one with the largest score; for all other measures it is the one with the smallest score.

Value

An object with S3 class "cv.l0ara" containing:

cv.error

Mean cross-validation score for each value in lambda.

cv.std

Estimated standard error of cv.error.

lam.min

The selected penalty value.

lambda

The supplied sequence of penalty values.

measure

The measure used for model selection.

family

The fitted model family.

x

The original design matrix.

y

The original response vector.

name

A printable label for measure.

fit.min

A "l0ara" object refit on the full data using lam.min.

Author(s)

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

See Also

l0ara, coef.cv.l0ara, plot.cv.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
lam <- c(0.1, 0.3, 0.5)
fit <- cv.l0ara(x, y, family="gaussian", lam, measure = "mse")

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)

Plot a "cv.l0ara" object

Description

Plot the cross-validation scores against the supplied penalty values and mark the selected lam.min.

Usage

## S3 method for class 'cv.l0ara'
plot(x, col = 3, ...)

Arguments

x

Fitted "cv.l0ara" object.

col

Color used for the plotted points.

...

Not used argument.

Value

Called for its side effect of producing a plot.

Author(s)

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

See Also

coef.cv.l0ara, cv.l0ara, l0ara.


Plot a "l0ara" object

Description

Plot fitted values against the linear predictor and, for logistic models, optionally add an ROC curve based on in-sample fitted probabilities.

Usage

## S3 method for class 'l0ara'
plot(x, auc = FALSE, split = FALSE, col = 4, ...)

Arguments

x

Fitted "l0ara" object.

auc

Logical; if TRUE and x$family == "logit", also draw an ROC curve.

split

Logical; if TRUE, do not change the graphics layout with par(mfrow = ...).

col

Color used for observed points and the ROC line.

...

Not used argument.

Value

Called for its side effect of producing one or two plots.

Author(s)

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

See Also

predict.l0ara, coef.l0ara, l0ara.


Make predictions from a "l0ara" object

Description

Generate linear predictors, response-scale predictions, class labels, or fitted coefficients from a "l0ara" fit.

Usage

## S3 method for class 'l0ara'
predict(
  object,
  newx,
  type = c("link", "response", "coefficients", "class"),
  ...
)

Arguments

object

Fitted "l0ara" object.

newx

Matrix of new predictor values. If omitted, predictions are made for the training design matrix stored in object$x.

type

Type of prediction required. "link" returns the linear predictor. "response" returns the response-scale mean implied by the model family. "coefficients" returns the fitted coefficient vector. "class" is available only for family = "logit" and returns 0/1 class labels using a cutoff of 0 on the linear predictor.

...

Not used argument.

Details

For Gaussian models, type = "link" and type = "response" return the same values.

Value

The return value depends on type: a numeric vector of linear predictors or response-scale predictions, a named coefficient vector, or a numeric vector of 0/1 class labels.

Author(s)

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

See Also

coef.l0ara, l0ara.


Print a "cv.l0ara" object

Description

Print a short summary of a cross-validated fit.

Usage

## S3 method for class 'cv.l0ara'
print(x, ...)

Arguments

x

Fitted "cv.l0ara" object.

...

Not used argument.

Value

Called for its side effect of printing cross-validation information.

Author(s)

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

See Also

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


Print a "l0ara" object

Description

Print a short summary of a fitted model.

Usage

## S3 method for class 'l0ara'
print(x, ...)

Arguments

x

Fitted "l0ara" object.

...

Not used argument.

Value

Called for its side effect of printing model information.

Author(s)

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

See Also

predict.l0ara, coef.l0ara, l0ara.

Need a high-speed mirror for your open-source project?
Contact our mirror admin team at info@clientvps.com.

This archive is provided as a free public service to the community.
Proudly supported by infrastructure from VPSPulse , RxServers , BuyNumber , UnitVPS , OffshoreName and secure payment technology by ArionPay.