| 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
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 |
y |
Response variable as in |
family |
Model family as in |
lam |
A user-supplied sequence of candidate penalty values. At least two values are required. |
measure |
Criterion used to compare folds. Use |
nfolds |
Number of folds. Default value is 10. Smallest value is 3. |
maxit |
Maximum number of iterations passed to each call to
|
eps |
Convergence threshold. Default value is |
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
|
cv.std |
Estimated standard error of |
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 |
fit.min |
A |
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 |
Model family. |
lam |
A single user-supplied penalty value. If you have a candidate
sequence of values, use |
standardize |
Logical flag indicating whether to standardize the columns
of |
maxit |
Maximum number of iterations passed to the fitting routine. |
eps |
Convergence threshold. Default value is |
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 |
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 |
split |
Logical; if |
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 |
type |
Type of prediction required. |
... |
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
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>