1
votes

I am using the sparse group lasso, which is a penalized regression. The package I am using is SGL. I tried to run the examples in my R, and the code is given as below

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")

I tried to extract the regression coefficient of cvFit, but it turns out to be

coef(cvFit)
NULL

Can anyone tell me what is wrong? Thanks in advance.

1
See str(cfFit) and determine the exact location of the coefficients.Roman Luštrik
@ Roman Luštrik what do you mean by determining the exact location of the coefficients?Xst67
Not familiar with this function but by typing cvFit you can see what values can be extracted. ie cvFit$fit$beta or cvFit$lambdasuser20650
cvFit$fit$beta contains a matrix of coefficients, one column for each lambda in the regularization path.davechilders
Post output of str function and I'll show you how to access the output.Roman Luštrik

1 Answers

0
votes

This extracts the coefficients from the model with the minimum lambda value.

coef(fit,s=cvfit$lambda.min)