Title: | Fit a GLM (or Cox Model) with a Combination of Lasso and Group Lasso Regularization |
---|---|
Description: | Fit a regularized generalized linear model via penalized maximum likelihood. The model is fit for a path of values of the penalty parameter. Fits linear, logistic and Cox models. |
Authors: | Noah Simon, Jerome Friedman, Trevor Hastie, and Rob Tibshirani |
Maintainer: | Noah Simon <[email protected]> |
License: | GPL |
Version: | 1.3 |
Built: | 2025-02-17 04:29:24 UTC |
Source: | https://github.com/cran/SGL |
Fit a regularized generalized linear model via penalized maximum likelihood. The model is fit for a path of values of the penalty parameter. Fits linear, logistic and Cox models.
Package: | SGL |
Type: | Package |
Version: | 1.0 |
Date: | 2012-3-12 |
License: | GPL |
LazyLoad: | yes |
Only 4 functions:
SGL
cvSGL
predictSGL
plot.cvSGL
Noah Simon, Jerome Friedman, Trevor Hastie, and Rob Tibshirani
Maintainer: Noah Simon <[email protected]>
Simon, N., Friedman, J., Hastie T., and Tibshirani, R. (2011)
A Sparse-Group Lasso,
http://faculty.washington.edu/nrsimon/SGLpaper.pdf
Fits and cross-validates a regularized generalized linear model via penalized maximum likelihood. The model is fit for a path of values of the penalty parameter, and a parameter value is chosen by cross-validation. Fits linear, logistic and Cox models.
cvSGL(data, index = rep(1, ncol(data$x)), type = "linear", maxit = 1000, thresh = 0.001, min.frac = 0.05, nlam = 20, gamma = 0.8, nfold = 10, standardize = TRUE, verbose = FALSE, step = 1, reset = 10, alpha = 0.95, lambdas = NULL, foldid = NULL)
cvSGL(data, index = rep(1, ncol(data$x)), type = "linear", maxit = 1000, thresh = 0.001, min.frac = 0.05, nlam = 20, gamma = 0.8, nfold = 10, standardize = TRUE, verbose = FALSE, step = 1, reset = 10, alpha = 0.95, lambdas = NULL, foldid = NULL)
data |
For |
index |
A p-vector indicating group membership of each covariate |
type |
model type: one of ("linear","logit", "cox") |
maxit |
Maximum number of iterations to convergence |
thresh |
Convergence threshold for change in beta |
min.frac |
The minimum value of the penalty parameter, as a fraction of the maximum value |
nlam |
Number of lambda to use in the regularization path |
gamma |
Fitting parameter used for tuning backtracking (between 0 and 1) |
nfold |
Number of folds of the cross-validation loop |
standardize |
Logical flag for variable standardization (scaling) prior to fitting the model. |
verbose |
Logical flag for whether or not step number will be output |
step |
Fitting parameter used for inital backtracking step size (between 0 and 1) |
reset |
Fitting parameter used for taking advantage of local strong convexity in nesterov momentum (number of iterations before momentum term is reset) |
alpha |
The mixing parameter. |
lambdas |
A user inputted sequence of lambda values for fitting. We recommend leaving this NULL and letting SGL self-select values |
foldid |
An optional user-pecified vector indicating the cross-validation fold in which each observation should be included. Values in this vector should range from 1 to nfold. If left unspecified, SGL will randomly assign observations to folds |
The function runs SGL
nfold
+1 times; the initial run is to find the lambda
sequence, subsequent runs are used to compute the cross-validated error rate and its standard deviation.
An object with S3 class "cv.SGL"
lldiff |
An |
llSD |
An |
lambdas |
The actual list of |
type |
Response type (linear/logic/cox) |
fit |
A model fit object created by a call to |
foldid |
A vector indicating the cross-validation folds that each observation is assigned to |
prevals |
A matrix of prevalidated predictions for each observation, for each lambda-value |
Noah Simon, Jerry Friedman, Trevor Hastie, and Rob Tibshirani
Maintainer: Noah Simon [email protected]
Simon, N., Friedman, J., Hastie, T., and Tibshirani, R. (2011)
A Sparse-Group Lasso,
http://faculty.washington.edu/nrsimon/SGLpaper.pdf
SGL
set.seed(1) n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) cvFit = cvSGL(data, index, type = "linear")
set.seed(1) n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) cvFit = cvSGL(data, index, type = "linear")
Plots the cross-validated error curve, and confidence bounds for each lambda
in our regularization path.
## S3 method for class 'cv.SGL' plot(x, ...)
## S3 method for class 'cv.SGL' plot(x, ...)
x |
fitted |
... |
additional arguments to be passed to plot |
A cross validated deviance plot is produced. More regularized models are to the right (less regularized to the left)
Noah Simon, Jerome Friedman, Trevor Hastie, and Rob Tibshirani
Maintainer: Noah Simon <[email protected]>
Simon, N., Friedman, J., Hastie T., and Tibshirani, R. (2011)
A Sparse-Group Lasso,
http://faculty.washington.edu/nrsimon/SGLpaper.pdf
SGL
and cv.SGL
.
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) cvFit = cvSGL(data, index, type = "linear") plot(cvFit)
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) cvFit = cvSGL(data, index, type = "linear") plot(cvFit)
Outputs predicted response values for new user input observations at a specified lambda
value
predictSGL(x, newX, lam)
predictSGL(x, newX, lam)
x |
fitted |
newX |
covariate matrix for new observations whose responses we wish to predict |
lam |
the index of the lambda value for the model with which we desire to predict |
Predicted outcomes are given
Noah Simon, Jerome Friedman, Trevor Hastie, and Rob Tibshirani
Maintainer: Noah Simon <[email protected]>
Simon, N., Friedman, J., Hastie T., and Tibshirani, R. (2011)
A Sparse-Group Lasso,
http://faculty.washington.edu/nrsimon/SGLpaper.pdf
SGL
and cvSGL
.
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) Fit = SGL(data, index, type = "linear") X.new = matrix(rnorm(n * p), ncol = p, nrow = n) predictSGL(Fit, X.new, 5)
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) Fit = SGL(data, index, type = "linear") X.new = matrix(rnorm(n * p), ncol = p, nrow = n) predictSGL(Fit, X.new, 5)
Prints a short summary of the SGL solution path.
## S3 method for class 'SGL' print(x, digits, ...)
## S3 method for class 'SGL' print(x, digits, ...)
x |
fitted |
digits |
significant digits in printout |
... |
additional print arguments |
The time of regression run, followed by a 2-column matrix with rows lambdas
and num.nonzero
. lambdas
gives the lambda-value of each fit. num.nonzero
gives the the number of non-zero coefficients.
Noah Simon, Jerome Friedman, Trevor Hastie, and Rob Tibshirani
Maintainer: Noah Simon <[email protected]>
Simon, N., Friedman, J., Hastie T., and Tibshirani, R. (2011)
A Sparse-Group Lasso,
http://faculty.washington.edu/nrsimon/SGLpaper.pdf
SGL
and cv.SGL
.
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) fit = SGL(data, index, type = "linear") print(fit)
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) fit = SGL(data, index, type = "linear") print(fit)
Fit a regularized generalized linear model via penalized maximum likelihood. The model is fit for a path of values of the penalty parameter. Fits linear, logistic and Cox models.
SGL(data, index, type = "linear", maxit = 1000, thresh = 0.001, min.frac = 0.1, nlam = 20, gamma = 0.8, standardize = TRUE, verbose = FALSE, step = 1, reset = 10, alpha = 0.95, lambdas = NULL)
SGL(data, index, type = "linear", maxit = 1000, thresh = 0.001, min.frac = 0.1, nlam = 20, gamma = 0.8, standardize = TRUE, verbose = FALSE, step = 1, reset = 10, alpha = 0.95, lambdas = NULL)
data |
For |
index |
A p-vector indicating group membership of each covariate |
type |
model type: one of ("linear","logit", "cox") |
maxit |
Maximum number of iterations to convergence |
thresh |
Convergence threshold for change in beta |
min.frac |
The minimum value of the penalty parameter, as a fraction of the maximum value |
nlam |
Number of lambda to use in the regularization path |
gamma |
Fitting parameter used for tuning backtracking (between 0 and 1) |
standardize |
Logical flag for variable standardization prior to fitting the model. |
verbose |
Logical flag for whether or not step number will be output |
step |
Fitting parameter used for inital backtracking step size (between 0 and 1) |
reset |
Fitting parameter used for taking advantage of local strong convexity in nesterov momentum (number of iterations before momentum term is reset) |
alpha |
The mixing parameter. |
lambdas |
A user specified sequence of lambda values for fitting. We recommend leaving this NULL and letting SGL self-select values |
The sequence of models along the regularization path is fit by accelerated generalized gradient descent.
An object with S3 class "SGL"
beta |
A p by |
lambdas |
The actual sequence of |
type |
Response type (linear/logic/cox) |
intercept |
For some model types, an intercept is fit |
X.transform |
A list used in |
lambdas |
A user specified sequence of lambda values for fitting. We recommend leaving this NULL and letting SGL self-select values |
Noah Simon, Jerry Friedman, Trevor Hastie, and Rob Tibshirani
Maintainer: Noah Simon [email protected]
Simon, N., Friedman, J., Hastie, T., and Tibshirani, R. (2011)
A Sparse-Group Lasso,
http://faculty.washington.edu/nrsimon/SGLpaper.pdf
cv.SGL
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) fit = SGL(data, index, type = "linear")
n = 50; p = 100; size.groups = 10 index <- ceiling(1:p / size.groups) X = matrix(rnorm(n * p), ncol = p, nrow = n) beta = (-2:2) y = X[,1:5] %*% beta + 0.1*rnorm(n) data = list(x = X, y = y) fit = SGL(data, index, type = "linear")