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
summary(time)
? $\endgroup$time
;glmnet
doesn't deal with those well. Those cases aren't providing useful information in any event. $\endgroup$