| Title: | Sparse Generalized Linear Model with L0 Approximation for Feature Selection |
|---|---|
| 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. |
| Authors: | Wenchuan Guo [aut, cre], Shujie Ma [aut], Zhenqiu Liu [aut] |
| Maintainer: | Wenchuan Guo <[email protected]> |
| License: | GPL-2 |
| Version: | 0.1.7 |
| Built: | 2026-05-28 07:38:57 UTC |
| Source: | https://github.com/cran/l0ara |
"cv.l0ara" objectReturn coefficients from the model refit at the selected
lam.min.
## S3 method for class 'cv.l0ara' coef(object, ...)## S3 method for class 'cv.l0ara' coef(object, ...)
object |
Fitted "cv.l0ara" object. |
... |
Not used argument. |
If object$fit.min is missing, the model is refit on the full
data using lam.min.
A named numeric vector of fitted coefficients.
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
predict.l0ara, l0ara,
cv.l0ara.
"l0ara" objectReturn the fitted coefficient vector.
## S3 method for class 'l0ara' coef(object, ...)## S3 method for class 'l0ara' coef(object, ...)
object |
Fitted "l0ara" object. |
... |
Not used argument. |
A named numeric vector of fitted coefficients.
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
Perform k-fold cross-validation over a supplied sequence of penalty values and return the value selected by the chosen measure.
cv.l0ara(x, y, family, lam, measure, nfolds, maxit, eps, seed)cv.l0ara(x, y, family, lam, measure, nfolds, maxit, eps, seed)
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. |
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.
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 |
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
l0ara, coef.cv.l0ara,
plot.cv.l0ara.
# 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")# 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 sparse generalized linear model by approximating the L0-penalized objective with an adaptive ridge algorithm.
l0ara(x, y, family, lam, standardize, maxit, eps)l0ara(x, y, family, lam, standardize, maxit, eps)
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 |
The objective function is
where is the number of non-zero elements of .
The adaptive ridge algorithm provides an efficient approximation to the
corresponding L0-penalized generalized linear model.
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. |
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
cv.l0ara, predict.l0ara,
coef.l0ara, plot.l0ara.
# 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)# 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)
"cv.l0ara" objectPlot the cross-validation scores against the supplied penalty
values and mark the selected lam.min.
## S3 method for class 'cv.l0ara' plot(x, col = 3, ...)## S3 method for class 'cv.l0ara' plot(x, col = 3, ...)
x |
Fitted "cv.l0ara" object. |
col |
Color used for the plotted points. |
... |
Not used argument. |
Called for its side effect of producing a plot.
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
coef.cv.l0ara, cv.l0ara,
l0ara.
"l0ara" objectPlot fitted values against the linear predictor and, for logistic models, optionally add an ROC curve based on in-sample fitted probabilities.
## S3 method for class 'l0ara' plot(x, auc = FALSE, split = FALSE, col = 4, ...)## S3 method for class 'l0ara' plot(x, auc = FALSE, split = FALSE, col = 4, ...)
x |
Fitted "l0ara" object. |
auc |
Logical; if |
split |
Logical; if |
col |
Color used for observed points and the ROC line. |
... |
Not used argument. |
Called for its side effect of producing one or two plots.
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
predict.l0ara, coef.l0ara,
l0ara.
"l0ara" objectGenerate linear predictors, response-scale predictions, class
labels, or fitted coefficients from a "l0ara" fit.
## S3 method for class 'l0ara' predict( object, newx, type = c("link", "response", "coefficients", "class"), ... )## S3 method for class 'l0ara' predict( object, newx, type = c("link", "response", "coefficients", "class"), ... )
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. |
For Gaussian models, type = "link" and
type = "response" return the same values.
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.
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
"cv.l0ara" objectPrint a short summary of a cross-validated fit.
## S3 method for class 'cv.l0ara' print(x, ...)## S3 method for class 'cv.l0ara' print(x, ...)
x |
Fitted "cv.l0ara" object. |
... |
Not used argument. |
Called for its side effect of printing cross-validation information.
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
coef.cv.l0ara, plot.cv.l0ara,
cv.l0ara, l0ara.
"l0ara" objectPrint a short summary of a fitted model.
## S3 method for class 'l0ara' print(x, ...)## S3 method for class 'l0ara' print(x, ...)
x |
Fitted "l0ara" object. |
... |
Not used argument. |
Called for its side effect of printing model information.
Wenchuan Guo <[email protected]>, Shujie Ma <[email protected]>, Zhenqiu Liu <[email protected]>
predict.l0ara, coef.l0ara,
l0ara.