# how to use method lasso in cox model using glmnet?

I have the survival data includes 252 patients, 25 independent variables and 35 events. I want to use lasso method in cox model to these data. I use glmnet for it. but, I encountered an error which I cannot explain or solve. I tried several times. Each times I get Error in coxnet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : negative event times encountered; not permitted for Cox family. can anyone help me solve this problem ?

r codes:

library(foreign)
attach(dataset)
library(glmnet)
library(survival)
x <- model.matrix( ~ group + sen + sex + B.G +  bmi + literacy + maritaly + job + smoking + db1 + db2 + db3 + db4 + db5 + a.d  + w + y.dialyz + h.f +
HCV + HBV + HIV + anemi + eprex - 1, dataset)
y <- Surv(time, status)
cv.fit <- cv.glmnet(x, y, family="cox", alpha=1)
fit=glmnet(x,y,family="cox", alpha=1)
plot(cv.fit)
cv.fit$lambda.min Coefficients <- coef(fit, s = cv.fit$lambda.min)
Active.Index <- which(Coefficients != 0)
Active.Coefficients <- Coefficients[Active.Index]


r output:

Error in coxnet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs,  :
negative event times encountered;  not permitted for Cox family

• Could you please show the result of summary(time)? – EdM Jul 28 '18 at 13:03
• @EdM - > summary(time) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.00 5.00 10.00 10.92 15.00 52.00 – shide Jul 28 '18 at 16:12
• Try removing cases with 0 values of time; glmnet doesn't deal with those well. Those cases aren't providing useful information in any event. – EdM Jul 28 '18 at 16:59
• i have replaced zero values of time with one. and again, i have run above codes. fortunately, no error found. thanks alot – shide Jul 29 '18 at 6:45