2
$\begingroup$

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)
dataset=read.spss("E:/dializ/data/total11.sav", to.data.frame=TRUE)
attach(dataset)
head(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
$\endgroup$
5
  • $\begingroup$ Could you please show the result of summary(time)? $\endgroup$
    – EdM
    Commented Jul 28, 2018 at 13:03
  • $\begingroup$ @EdM - > summary(time) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.00 5.00 10.00 10.92 15.00 52.00 $\endgroup$
    – shide
    Commented Jul 28, 2018 at 16:12
  • 2
    $\begingroup$ 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. $\endgroup$
    – EdM
    Commented Jul 28, 2018 at 16:59
  • $\begingroup$ i have replaced zero values of time with one. and again, i have run above codes. fortunately, no error found. thanks alot $\endgroup$
    – shide
    Commented Jul 29, 2018 at 6:45
  • $\begingroup$ The same error occured when I analyze the survivla data of Pancreatic cancer form ICGC for determine its relationship betweem certain gene expression level and survival time. The cv.glmnet command can make its function after deleting those patient samples with survival time equal to zero. $\endgroup$
    – Haibara
    Commented Jul 21, 2021 at 7:44

1 Answer 1

2
$\begingroup$

Try coding x and y in below order and this might work

y <- Surv(time, status)

x <- model.matrix(y ~ 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)

$\endgroup$
2
  • 3
    $\begingroup$ ???? this doesn't make sense to me. Can you explain the logic behind your answer? $\endgroup$
    – Ben Bolker
    Commented Dec 29, 2018 at 14:05
  • $\begingroup$ Not sure why this is downvoted. It appears correct to me. $\endgroup$ Commented Jan 24, 2020 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.