4

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!

zx8754
  • 52,746
  • 12
  • 114
  • 209
EsBee
  • 231
  • 2
  • 13
  • Without out data to make this error [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), it will be very difficult to help you. – MrFlick Jan 16 '15 at 18:37
  • @MrFlick: I am trying to upload the data...but its too big of a file. – EsBee Jan 16 '15 at 18:44
  • We don't need your exact input file. See the tips in the link I provided for creating a representative input data set. It just has to be enough to trigger the exact same error you are getting. – MrFlick Jan 16 '15 at 18:45

1 Answers1

5

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

Branden Murray
  • 484
  • 2
  • 10
  • 1
    Thanks @Branden Murray! I found that the data set indeed had some 0's. The model ran when the 0s are removed – EsBee Jan 16 '15 at 19:05