% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wrapper.R
\name{surv.xgboost}
\alias{surv.xgboost}
\title{Wrapper for XGBoost (Robust CV-Tuned + Safe Prediction)}
\usage{
surv.xgboost(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights,
  id,
  nrounds = 1000,
  early_stopping_rounds = 10,
  eta = 0.05,
  max_depth = 2,
  min_child_weight = 5,
  lambda = 10,
  subsample = 0.7,
  ...
)
}
\arguments{
\item{time}{Observed follow-up time.}

\item{event}{Observed event indicator.}

\item{X}{Training covariate data.frame.}

\item{newdata}{Test covariate data.frame to use for prediction.}

\item{new.times}{Times at which to obtain the predicted survivals.}

\item{obsWeights}{Observation weights.}

\item{id}{Optional cluster/individual ID indicator.}

\item{nrounds}{Max number of boosting iterations (default: 1000).}

\item{early_stopping_rounds}{Rounds with no improvement to trigger early stopping (default: 10).}

\item{eta}{Learning rate (default: 0.05).}

\item{max_depth}{Maximum tree depth (default: 2).}

\item{min_child_weight}{Minimum sum of instance weight in a child (default: 5).}

\item{lambda}{L2 regularization term on weights (default: 10).}

\item{subsample}{Subsample ratio of the training instances (default: 0.7).}

\item{...}{Additional arguments passed to \code{\link[xgboost]{xgb.train}}.}
}
\value{
A list containing:
\itemize{
\item \code{fit}: The fitted model object (e.g., the raw \code{coxph} or \code{xgb.Booster} object).
If the model fails to fit, this may be an object of class \code{try-error}.
\item \code{pred}: A numeric matrix of cross-validated survival predictions
evaluated at the specified \code{new.times} grid.
}
}
\description{
Estimates a Cox proportional hazards model via XGBoost.
Incorporates safe Breslow hazard calculation and matrix alignment to prevent C++ crashes.
}
\examples{
if (requireNamespace("xgboost", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:30, ]
  x_cols <- grep("^x", names(dat))[1:3]
  X <- dat[, x_cols, drop = FALSE]
  newX <- X[1:5, , drop = FALSE]
  times <- seq(50, 150, by = 50)

  fit <- surv.xgboost(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    nrounds = 5,
    early_stopping_rounds = 2,
    max_depth = 1
  )

  dim(fit[["pred"]])
}
}
