Reputation: 408
I am using glmnet
(version 4.1-2) with cv.glmnet
to fit a Lasso model. Based on the vignettes, you can use intercept = FALSE
in glmnet::glmnet
, so I thought I could do the same also with cv.glmnet
, but if I use the same argument and I print the list of coefficients resulting from cv.glmnet
, (Intercept)
is still there and some of the values are different from zero. Any suggestion on how to do CV without fitting the intercept?
Forgot to mention that I am doing multi-task learning. That is, my y
is a matrix of responses rather than a vector:
cv.mfit <- glmnet::cv.glmnet(x = as.matrix(dat.preprocessed$exposures), # nxp
y = as.matrix(dat.preprocessed$omics), # nxq
family = "mgaussian", alpha = 1,
standardize = FALSE, standardize.response = FALSE,
intercept = FALSE)
Upvotes: 1
Views: 1048
Reputation: 46968
I cannot reproduce your issue, I am on glmnet_4.1-1
and if I set intercept=FALSE
, I get all 0s for intercepts:
library(glmnet)
x = as.matrix(mtcars[,1:9])
y = as.matrix(mtcars[,10:11])
fit = glmnet(x=x,y=y,alpha=1,intercept=FALSE,family="mgaussian")
table(fit$a0)
0
200
cvfit = cv.glmnet(x=x,y=y,alpha=1,intercept=FALSE,family="mgaussian")
table(cvfit$glmnet.fit$a0)
0
200
cv.mfit = glmnet::cv.glmnet(x = x,y = y,
family = "mgaussian", alpha = 1,
standardize = FALSE,
standardize.response = FALSE,
intercept = FALSE)
table(cv.mfit$glmnet.fit$a0)
0
200
Upvotes: 0