Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 )
- 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
Add Comment
Please, Sign In to add comment