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.
str(cfFit)
and determine the exact location of the coefficients. – Roman LuštrikcvFit
you can see what values can be extracted. iecvFit$fit$beta
orcvFit$lambdas
– user20650cvFit$fit$beta
contains a matrix of coefficients, one column for eachlambda
in the regularization path. – davechildersstr
function and I'll show you how to access the output. – Roman Luštrik