I am now working on a project which involves using xgboost package in R for right-censored time-to-event endpoints from a two-arm simulation study. It seems like xgboost package does not have built-in objective function for the right-censored time-to-event data, so I wrote my customized objective function, which is the negative log partial likelihood according to the survcomp package as
survobj <- function(preds, dtrain) {
labels <- getinfo(dtrain, "label")
n <- length(preds)
r <- rank(labels)
ita <- preds
expita <- exp(ita)
dono <- rep(0, n)
grad.dono <- rep(0, n)
for (i in 1:n) {
dono[i] <- sum(expita[r >= r[i]])
# derivative of dono
grad.dono[i] <- sum(t.mod[r >= r[i]] * expita[r >= r[i]])
}
# gradient and hessian of the log partial likelihood
# llk <- -(ita - log(dono))*event ### negative log partial likelihood
grad <- -(t.mod - grad.dono / dono)*event
hess <- (dono^2 - grad.dono^2)/ dono^2 * event
return(list(grad = grad, hess = hess))
}
Since this customized objective function involves the treatment group, and the censoring index. My question is that is there any way to pass group treatment indicator and the censoring index into the customized objective function as additional arguments? I found that the argument dtrain is of DMatrix class, and it may be possible to carry those information by changing the structure of DMatrix, is there any way to pass those information in the DMatrix?
Thanks,
Hesen