0
$\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$
  • $\begingroup$ Could you please show the result of summary(time)? $\endgroup$ – EdM Jul 28 '18 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 Jul 28 '18 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 Jul 28 '18 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 Jul 29 '18 at 6:45
-1
$\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$
  • 3
    $\begingroup$ ???? this doesn't make sense to me. Can you explain the logic behind your answer? $\endgroup$ – Ben Bolker Dec 29 '18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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