| Title: | Graph-Constrained Regularization for Sparse Generalized Linear Models |
|---|---|
| Description: | We propose to use sparse regression model to achieve variable selection while accounting for graph-constraints among coefficients. Different linear combination of a sparsity penalty(L1) and a smoothness(MCP) penalty has been used, which induces both sparsity of the solution and certain smoothness on the linear coefficients. |
| Authors: | Li Chen, Jun Chen |
| Maintainer: | Li Chen <[email protected]> |
| License: | GPL-2 |
| Version: | 1.0.3 |
| Built: | 2026-09-17 08:51:01 UTC |
| Source: | https://github.com/cran/glmgraph |
Fit a generalized linear model at grids of tuning parameter via penalized maximum likelihood. The regularization path is computed for a combination of sparse and smooth penalty at two grids of values for the regularization parameter lambda1(Lasso or MCP penalty) and lambda2(Laplacian penalty). Fits linear, logistic regression models.
| Package: | glmgraph |
| Type: | Package |
| Version: | 1.0-0 |
| Date: | 2015-03-11 |
| License: | GPL-2 |
The algorithm accepts a design matrix X, a vector of responses Y and a Laplacian matrix L.
Produces the regularization path over the grid of tuning parameter lambda1 and lambda2.
It consists of the following main functions glmgraphcv.glmgraphplot.glmgraphcoef.glmgraphpredict.glmgraph
Li Chen <[email protected]>, Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen(2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## Construct Adjacency and Laplacian matrices A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L,family="gaussian") plot(obj) betas <- coef(obj) betas <- coef(obj,lambda1=c(0.1,0.2)) yhat <- predict(obj,X,type="response") cv.obj <- cv.glmgraph(X,Y,L) plot(cv.obj) beta.min <- coef(cv.obj) yhat.min <- predict(cv.obj,X)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## Construct Adjacency and Laplacian matrices A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L,family="gaussian") plot(obj) betas <- coef(obj) betas <- coef(obj,lambda1=c(0.1,0.2)) yhat <- predict(obj,X,type="response") cv.obj <- cv.glmgraph(X,Y,L) plot(cv.obj) beta.min <- coef(cv.obj) yhat.min <- predict(cv.obj,X)
Retrieve coefficients from a fitted "cv.glmgraph" object based on the chosen regularization parameters from cross validation.
## S3 method for class 'cv.glmgraph' coef(object,s,...)## S3 method for class 'cv.glmgraph' coef(object,s,...)
object |
Fitted |
s |
Either |
... |
Other parameters to |
Li Chen <[email protected]> , Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
predict.cv.glmgraph,cv.glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) beta.min <- coef(cv.obj)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) beta.min <- coef(cv.obj)
Retrieve coefficients from a fitted "glmgraph" object, depending on the user-specified regularization parameters.
## S3 method for class 'glmgraph' coef(object,lambda1,lambda2,...)## S3 method for class 'glmgraph' coef(object,lambda1,lambda2,...)
object |
Fitted |
lambda1 |
Values of the regularization parameter |
lambda2 |
The user-specified regularization |
... |
Other parameters to |
If lambda1 and lambda2 are missing, all coefficients of fitted glmgraph object will be returned.
If only lambda1 is missing, then coefficients of specified lambda2 will be returned.
The object returned depends on type.
Li Chen <[email protected]>, Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
predict.glmgraph,glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L) coefs <- coef(obj) coefs <- coef(obj,lambda2=0.01) coefs <- coef(obj,lambda1=c(0.11,0.12)) coefs <- coef(obj,lambda1=c(0.11,0.12),lambda2=0.01)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L) coefs <- coef(obj) coefs <- coef(obj,lambda2=0.01) coefs <- coef(obj,lambda1=c(0.11,0.12)) coefs <- coef(obj,lambda1=c(0.11,0.12),lambda2=0.01)
Performs k-fold cross validation for glmgraph
cv.glmgraph(X,Y,L,...,type.measure=c("mse","mae","deviance","auc"),nfolds=5,trace=TRUE)cv.glmgraph(X,Y,L,...,type.measure=c("mse","mae","deviance","auc"),nfolds=5,trace=TRUE)
X |
|
Y |
Response |
L |
User-specified Laplacian matrix |
... |
Additional arguments as in |
type.measure |
if |
nfolds |
The number of cross-validation folds. Default is 5. |
trace |
Print out the cross validation steps if |
The function runs glmgraph nfolds+1 times; the
first to get the lambda1 and lambda2 sequence, and then the remainder to
compute the fit with each of the folds omitted. The error is
accumulated, and the average error and standard deviation over the
folds is computed.
Note also that the results of cv.glmgraph are
random, since the folds are selected at random. Users can reduce this
randomness by running cv.glmgraph many times, and averaging the
error curves.
An object "cv.glmgraph" containing:
obj |
The fitted |
cvmat |
A data frame summarized cross validation results, which could be obtained by |
cvm |
The mean cross-validated |
cvsd |
The estimate of standard error of |
cvmin |
Best cross-validation |
cv.1se |
Simliar to |
lambda1.min |
Coupled with |
lambda2.min |
Coupled with |
lambda1.1se |
Coupled with |
lambda2.1se |
Coupled with |
beta.min |
Estimated beta with best |
beta.1se |
Estimated beta with best |
Li Chen <[email protected]> , Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen(2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
glmgraph,coef.cv.glmgraph,predict.cv.glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L,penalty="lasso",lambda2=c(0,1.28)) beta.min <- coef(cv.obj) print(cv.obj) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) cv.obj <- cv.glmgraph(X,Y,L,family="binomial",lambda2=c(0,1.28),penalty="lasso",type.measure="auc") beta.min <- coef(cv.obj) print(cv.obj)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L,penalty="lasso",lambda2=c(0,1.28)) beta.min <- coef(cv.obj) print(cv.obj) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) cv.obj <- cv.glmgraph(X,Y,L,family="binomial",lambda2=c(0,1.28),penalty="lasso",type.measure="auc") beta.min <- coef(cv.obj) print(cv.obj)
Fit a generalized linear model at grids of tuning parameter via penalized maximum likelihood. The regularization path is computed for a combination of sparse and smooth penalty at two grids of values for the regularization parameter lambda1(Lasso or MCP penalty) and lambda2(Laplacian penalty). Fits linear, logistic regression models.
glmgraph(X, Y, L, family=c("gaussian","binomial"), penalty=c("MCP","lasso") , mcpapproach=c("mmcd", "adaptive", "original"),gamma=8, lambda1,nlambda1=100,lambda2=c(0, 0.01 * 2^(0:7)),eps=1e-3,max.iter=2000, dfmax=round(ncol(X)/2),penalty.factor=rep(1,ncol(X)),standardize=TRUE,warn=FALSE,...)glmgraph(X, Y, L, family=c("gaussian","binomial"), penalty=c("MCP","lasso") , mcpapproach=c("mmcd", "adaptive", "original"),gamma=8, lambda1,nlambda1=100,lambda2=c(0, 0.01 * 2^(0:7)),eps=1e-3,max.iter=2000, dfmax=round(ncol(X)/2),penalty.factor=rep(1,ncol(X)),standardize=TRUE,warn=FALSE,...)
X |
Input matrix; each row is an observation vector. |
Y |
Response vector. Quantitative for |
family |
Either "gaussian", "binomial", depending on the response. |
L |
User-specified Laplacian matrix. |
penalty |
The sparse penalty to be applied to the model. Either "MCP" (the default), or "lasso". |
mcpapproach |
For |
gamma |
The tuning parameter of the MCP penalty.The default value is 8. |
nlambda1 |
The number of |
lambda1 |
A user-specified sequence of |
lambda2 |
A user-specified sequence of |
eps |
Convergence threshold for coordinate descent. Each inner
coordinate-descent loop continues until the relative change in the
objective function is less than |
max.iter |
Maximum number of passes over the data for all |
dfmax |
Limit the maximum number of variables in the
model. Useful for very large |
penalty.factor |
A multiplicative factor for the penalty applied
to each coefficient. If supplied, |
standardize |
Logical flag for x variable standardization, prior to
fitting the model sequence. The coefficients are always returned on
the original scale. Default is |
warn |
Return warning messages for failures to converge and model selection issues. Default is FALSE. |
... |
Other parameters to |
An object "glmgraph" containing:
betas |
A list of fitted coefficients. The number of rows for each matrix is equal to the number of coefficients, and the number of columns is smaller or equal to |
lambda1s |
A list of vector. Each vector is a sequence of used |
lambda2 |
A sequence of |
loglik |
A list of log likelihood for each value of |
df |
A list of the number of nonzero values for each value of |
Li Chen <[email protected]>, Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
plot.glmgraph, cv.glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### construct laplacian matrix from adjacency matrix diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L,family="gaussian") plot(obj) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) obj <- glmgraph(X,Y,L,family="binomial") plot(obj)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### construct laplacian matrix from adjacency matrix diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L,family="gaussian") plot(obj) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) obj <- glmgraph(X,Y,L,family="binomial") plot(obj)
Plots the cross-validation curve for the "cv.glmgraph" object, along with standard error bars.
## S3 method for class 'cv.glmgraph' plot(x,...)## S3 method for class 'cv.glmgraph' plot(x,...)
x |
A |
... |
Other graphical parameters to |
Li Chen <[email protected]> , Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
glmgraph, cv.glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### construct laplacian matrix from adjacency matrix diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) plot(cv.obj)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### construct laplacian matrix from adjacency matrix diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) plot(cv.obj)
Plot solution path for a fitted
"glmgraph" object.
## S3 method for class 'glmgraph' plot(x,...)## S3 method for class 'glmgraph' plot(x,...)
x |
Fitted |
... |
Other graphical parameters to |
Li Chen <[email protected]> , Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ### construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L) plot(obj) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) obj <- glmgraph(X,Y,L,family="binomial") plot(obj)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ### construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L) plot(obj) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) obj <- glmgraph(X,Y,L,family="binomial") plot(obj)
This function makes predictions from a cross-validated glmgraph model,
using the stored "cv.glmgraph" object, and the optimal value
chosen for lambda1 and lambda2.
## S3 method for class 'cv.glmgraph' predict(object,X,s=c("lambda1.min","lambda1.1se"), type=c("response", "coefficients","class", "nzeros","link"),...)## S3 method for class 'cv.glmgraph' predict(object,X,s=c("lambda1.min","lambda1.1se"), type=c("response", "coefficients","class", "nzeros","link"),...)
object |
Fitted |
X |
Matrix at which predictions are to be made. |
s |
Either |
type |
Type of prediction: |
... |
Other parameters to |
Li Chen <[email protected]> , Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
cv.glmgraph,coef.cv.glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ### construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) beta.min <- predict(cv.obj,X,type="coefficients")set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ### construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) beta.min <- predict(cv.obj,X,type="coefficients")
Similar to other predict methods, this function returns predictions from
a fitted "glmgraph" object.
## S3 method for class 'glmgraph' predict(object, X, type=c("response", "coefficients", "class", "nzeros","link"), lambda1, lambda2,...)## S3 method for class 'glmgraph' predict(object, X, type=c("response", "coefficients", "class", "nzeros","link"), lambda1, lambda2,...)
object |
Fitted |
X |
Matrix of values at which predictions are to be made. |
lambda1 |
Values of the regularization parameter |
lambda2 |
Values of the regularization parameter |
type |
Type of prediction: |
... |
Other parameters to |
Li Chen <[email protected]> , Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L) res <- predict(obj, X, type="link", lambda1=0.05,lambda2=0.01) res <- predict(obj, X, type="response", lambda1=0.05,lambda2=0.01) res <- predict(obj,X,type="nzeros",lambda1=0.05,lambda2=0.01) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) obj <- glmgraph(X,Y,L,family="binomial") res <- predict(obj,X,type="class",lambda1=c(0.05,0.06),lambda2=c(0.02,0.16,0.32))set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 ## construct laplacian matrix from adjacency matrix A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) obj <- glmgraph(X,Y,L) res <- predict(obj, X, type="link", lambda1=0.05,lambda2=0.01) res <- predict(obj, X, type="response", lambda1=0.05,lambda2=0.01) res <- predict(obj,X,type="nzeros",lambda1=0.05,lambda2=0.01) ### binomial Y <- rbinom(n,1,prob=1/(1+exp(-eta))) obj <- glmgraph(X,Y,L,family="binomial") res <- predict(obj,X,type="class",lambda1=c(0.05,0.06),lambda2=c(0.02,0.16,0.32))
Print a summary of the cv.glmgraph solution path information during cross validation
## S3 method for class 'cv.glmgraph' print(x, ...)## S3 method for class 'cv.glmgraph' print(x, ...)
x |
fitted |
... |
Other parameters to |
The call prints the cvmat object from a fitted cv.glmgraph object.
The call also prints the chosen regularization parameters lambda1 and lambda2 along with best cv.type(minimum "mse" or "mae" if family is "gaussian"; maximum "auc" or minimum "deviance" if family is "binomial") after cross validation.
Li Chen <[email protected]> , Jun Chen <[email protected]>
Li Chen. Han Liu. Hongzhe Li. Jun Chen. (2015) glmgraph: Graph-constrained Regularization for Sparse Generalized Linear Models.(Working paper)
cv.glmgraph
set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### construct laplacian matrix from adjacency matrix diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) print(cv.obj)set.seed(1234) library(glmgraph) n <- 100 p1 <- 10 p2 <- 90 p <- p1+p2 X <- matrix(rnorm(n*p), n,p) magnitude <- 1 A <- matrix(rep(0,p*p),p,p) A[1:p1,1:p1] <- 1 A[(p1+1):p,(p1+1):p] <- 1 diag(A) <- 0 btrue <- c(rep(magnitude,p1),rep(0,p2)) intercept <- 0 eta <- intercept+X%*%btrue ### construct laplacian matrix from adjacency matrix diagL <- apply(A,1,sum) L <- -A diag(L) <- diagL ### gaussian Y <- eta+rnorm(n) cv.obj <- cv.glmgraph(X,Y,L) print(cv.obj)