I am running a coxph model using glmnet. The following is the code that I am using:
data <- read.csv("CSM Tiers by Org.csv", stringsAsFactors = FALSE, na.strings = "?")
x <- model.matrix(~ data$CSM + data$Exclude + data$Queue)
y <- data$Time
status <- data$Event
glmnet(x,Surv(y,status), family = "cox")
However, I am getting the following error:
Error in coxnet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, :
negative event times encountered; not permitted for Cox family
But I dont see any negative event times in my data.
> sum(y<0)
[1] 0
Any help is greatly appreciated!
Check if sum(y<=0). The code in the function says it will return that error if y's equal 0 as well.
Code is here, error you're referencing is on line 5: https://github.com/jeffwong/glmnet/blob/master/R/coxnet.R