3

I am studing variable selection using LASSO (least absolute shrinkage and selection operator) with Cox model, I use two R packages glmnet and penalized. I use cv.glmnet and optL1 to find the optimal shrinkage parameter $\lambda$.

My question is : Why I get different results of $\lambda$ when I use cv.glmnet and optL1 of penalized?

This is my R code :

library(glmnet) 

n=500

p=30 

nzc=trunc(p/10) 

x=matrix(rnorm(n*p),n,p)  

beta=rnorm(nzc) 

fx=x[,seq(nzc)]%*%beta/3  

hx=exp(fx) 

ty=rexp(n,hx)  

tcens=rbinom(n=n,prob=.3,size=1) 

y=cbind(time=ty,status=1-tcens) 

NFOLD = 5 

foldid=sample(rep(seq(NFOLD),length=n)) 

fit1_cv = cv.glmnet(x,y,family="cox",foldid=foldid, thresh = 1e-16) 

fit1_cv$lambda.min 

library(penalized) 

cv.penal <- optL1(Surv(y[, 'time'], y[, 'status']), penalized = x, fold = foldid) 

cv.penal$lambda 

cv.penal$fullfit@penalized 

fit1_cv$cvm 

whichLambda <- which( fit1_cv$lambda == fit1_cv$lambda.min ) 

fit <- glmnet(x,y,family="cox",lambda = fit1_cv$lambda.min, thresh = 1e-16) 

res <- cbind(CV.GLMNET = fit1_cv$glmnet.fit$beta [, whichLambda], 

'GLMNET.NAIF' = as.numeric(fit$beta), 

'penalized' = cv.penal$fullfit@penalized) 

res #different Lambda => different beta !
Ph.D.Student
  • 704
  • 6
  • 27
  • What criteria are these various algorithms "optimizing"? There's some disagreement in the literature about how to calculate the BIC for a Cox model. Some say the "n" is the number of observations, others (like myself) say "n" should be the number of *events*/failures. This is more conservative and would lead to a larger optimal $\lambda$ penalty. – AdamO Mar 01 '18 at 19:45

0 Answers0