0

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

  • You can add any parameters you want to a function so it's a bit unclear where you are asking. Maybe show the code where you are trying to use this function? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 03 '20 at 19:32
  • Mu question is not about general R functions. Instead, it is about the customized objective function in xgboost R package. It takes "preds" and "dtrain" as arguments, which pass outcome and design matrix into the function. Whereas, my objective function has a little bit more info, such as trt group index and censoring index. If I use the global variables, it won't go through the cross validation. I am just wondering how can I pass the additional information into the function (through DMatrix)? – Hesen Li Feb 04 '20 at 17:24

0 Answers0