
Cross-validation of conditional average treatment-effect scores for survival outcomes
Source:R/crossv.R
catecvsurv.RdRepeatedly fits scores on training data and applies them to validation data. Subgroup effects include restricted mean time lost ratios and marginal cumulative hazard ratios at the specified horizon. Cox, Weibull and log-normal T-learners use training-arm outcome models to predict restricted mean time lost in both sets.
Usage
catecvsurv(
data,
outcome_model,
outcome_method = "coxph",
benefit_model = NULL,
benefit_method = "t_learner",
ps_model,
ps_method = "glm",
censoring_model = NULL,
censoring_method = "breslow",
minPS = 0.01,
maxPS = 0.99,
followup.time = NULL,
tau0 = NULL,
higher.y = TRUE,
prop.cutoff = seq(0.5, 1, length = 6),
prop.multi = c(0, 1/3, 2/3, 1),
abc = TRUE,
train.prop = 3/4,
cv.n = 10,
error.max = 0.1,
max.iter = 5000,
surv.min = 0.025,
tree.depth = 2,
n.trees.rf = 1000,
n.trees.boosting = 200,
B = 3,
Kfold = 5,
error.maxNR = 0.001,
max.iterNR = 150,
tune = c(0.5, 2),
seed = NULL,
plot.gbmperf = FALSE,
verbose = 0,
rmst.control = list(),
contrast.control = list(),
ps.control = list(),
rf.control = list(),
...
)Arguments
- data
A data frame containing the variables in the outcome, treatment, and censoring models (if specified); a data frame with
nrows (1 row per observation).- outcome_model
A formula specifying the outcome and baseline covariates. Use a
Survresponse for survival and include an exposure offset for count outcomes.- outcome_method
Outcome-model method for each
benefit_method. For a T-learner, the default is'coxph'. Other options include'weibull','log_normal','poisson','boosting', and'random_forest'. For two-regression or contrast regression, choose'fractional_logit','boosting', or'random_forest'.- benefit_model
Optional one-sided formula for the covariates and terms used in two-regression and contrast-regression scores. The default uses the terms in
outcome_model. T-learners useoutcome_modeldirectly.- benefit_method
Score-construction method, with one entry per
outcome_method. The default is't_learner'. Seecatefitfor supported combinations.- ps_model
A formula for the treatment model, with treatment on the left. It estimates propensity scores. For a common randomization probability, use an intercept-only formula such as
trt ~ 1.- ps_method
Treatment-model fitting method. The default
'glm'uses logistic regression.'lasso'uses a logistic model with LASSO screening for two-way interactions.- censoring_model
Survival only. A one-sided formula for the model that estimates probabilities of remaining uncensored for inverse probability of censoring weighting (IPCW). The default uses the outcome-model covariates and treatment.
- censoring_method
Survival only.
'breslow'(default) uses Cox regression with the Breslow estimator. Accelerated failure time options are'aft (exponential)','aft (weibull)','aft (lognormal)', and'aft (loglogistic)'.- minPS
A numerical value (in `[0, 1]`) below which estimated propensity scores should be truncated. Default is
0.01.- maxPS
A numerical value (in `(0, 1]`) above which estimated propensity scores should be truncated. Must be strictly greater than
minPS. Default is0.99.- followup.time
A column name in
dataspecifying the maximum follow-up time, interpreted as the potential censoring time. Default isfollowup.time = NULL, which corresponds to unknown potential censoring time.- tau0
The truncation time for defining restricted mean time lost. Default is
NULL, which corresponds to setting the truncation time as the maximum survival time in the data.- higher.y
A logical value indicating whether higher (
TRUE) or lower (FALSE) values of the outcome are more desirable. Default isTRUE.- prop.cutoff
A vector of numerical values (in `(0, 1]`) specifying percentiles of the estimated log CATE scores to define nested subgroups. Each element represents the cutoff to separate observations in nested subgroups (below vs above cutoff). The length of
prop.cutoffis the number of nested subgroups. An equally-spaced sequence of proportions ending with 1 is recommended. Default isseq(0.5, 1, length = 6).- prop.multi
A vector of numerical values (in `[0, 1]`) specifying percentiles of the estimated log CATE scores to define mutually exclusive subgroups. It should start with 0, end with 1, and be of
length(prop.multi) > 2. Each element represents the cutoff to separate the observations intolength(prop.multi) - 1mutually exclusive subgroups. Default isc(0, 1/3, 2/3, 1).- abc
A logical value indicating whether the area between curves (ABC) should be calculated at each cross-validation iterations, for each scoring method. Default is
TRUE.- train.prop
A numerical value (in `(0, 1)`) indicating the proportion of total data used for training. Default is
3/4.- cv.n
A positive integer value indicating the number of cross-validation iterations. Default is
10.- error.max
A numerical value > 0 indicating the tolerance (maximum value of error) for the largest standardized absolute difference in the covariate distributions or in the doubly robust estimated rate ratios between the training and validation sets. This is used to define a balanced training-validation splitting. Default is
0.1.- max.iter
A positive integer value indicating the maximum number of iterations when searching for a balanced training-validation split. Default is
5,000.- surv.min
Lower bound for the estimated probability of remaining uncensored. Defaults to 0.025.
- tree.depth
Maximum depth of boosting trees. Defaults to 2.
- n.trees.rf
Number of trees for survival random forests. Defaults to 1000.
- n.trees.boosting
Maximum number of trees for boosting. Defaults to 200.
- B
Number of cross-fitting repetitions used by two-regression and contrast regression. Defaults to 3.
- Kfold
Number of folds used for cross-fitting within each training set. Defaults to 5.
- error.maxNR
Newton–Raphson convergence tolerance for contrast regression. Defaults to 0.001.
- max.iterNR
Maximum number of Newton–Raphson iterations for contrast regression. Defaults to 150.
- tune
Two positive Newton–Raphson tuning values for contrast regression. Defaults to
c(0.5, 2).- seed
An optional integer specifying an initial randomization seed for reproducibility. Default is
NULL, corresponding to no seed.- plot.gbmperf
Whether to plot boosting performance. Defaults to FALSE.
- verbose
An integer value indicating what kind of intermediate progress messages should be printed.
0means no outputs.1means only progress bar and run time.2means progress bar, run time, and all errors and warnings. Default is0.- rmst.control
Named options for Cox restricted mean survival integration. Supported entry:
solver = "C"(default) orsolver = "R". The C backend accumulates each patient's integral without allocating a patient-by-event-time matrix. Cox model fitting is unchanged. Available only for survival outcomes; independent ofcontrast.control.- contrast.control
A named list of contrast-regression options:
solver("C", the default, or"R"),error.maxNR,max.iterNR,tune, andoptim.control(a named list passed tostats::optimon fallback). List entries override top-level NR arguments. This is independent ofrmst.control, which selects RMST integration, and is not passed to boosting via....- ps.control
Named options for LASSO propensity-score interaction screening. Supported entry:
solver = "C"(default) orsolver = "R". Only affects screening whenps_method = "lasso"; the LASSO fit and interaction selection rule are unchanged. Kept separate from boosting's...and other numerical controls.- rf.control
Named list of randomForestSRC options:
mtry,nodesize,nsplit,nodedepth, andsplitrule. Applies to both treatment arms and survival initial-predictor forests. Usen.trees.rffor the number of trees.- ...
Additional arguments. Deprecated argument names from precmed 1.1.0 remain supported for backward compatibility and emit warnings.
Value
A "precmed" object with the components below. When doubly
robust scores use different outcome methods, outcome_methods
records the method used for each score.
ate.randomForest: A list of ATE output measured by the RMTL ratio if the selected scoring methods includes'randomForest':ate.est.train.high.cv: A matrix of numerical values withlength(prop.cutoff)rows andcv.ncolumns. The ith column/jth row cell contains the estimated ATE in the nested subgroup of high responders defined by CATE score above (ifhigher.y = FALSE) or below (ifhigher.y = TRUE) theprop.cutoff[j]x100% percentile of the estimated CATE score in the training set in the ith cross-validation iteration.ate.est.train.low.cv: A matrix of numerical values withlength(prop.cutoff) - 1rows andcv.ncolumns. TThe ith column/jth row cell contains the estimated ATE in the nested subgroup of low responders defined by CATE score below (ifhigher.y = FALSE) or above (ifhigher.y = TRUE) theprop.cutoff[j]x100% percentile of the estimated CATE score in the training set in the ith cross-validation iteration.ate.est.valid.high.cv: Same asate.est.train.high.cv, but in the validation set.ate.est.valid.low.cv: Same asate.est.train.low.cv, but in the validation set.ate.est.train.group.cv: A matrix of numerical values withlength(prop.multi) - 1rows andcv.ncolumns. The ith column contains the estimated ATE inlength(prop.multi) - 1mutually exclusive subgroups defined byprop.multiin the training set in ith cross-validation iteration.ate.est.valid.group.cv: Same asate.est.train.group.cv, but in the validation set.abc.valid: A vector of numerical values of lengthcv.n, The ith element returns the ABC of the validation curve in the ith cross-validation iteration. Only returned ifabc = TRUE.
ate.boosting: A list of results similar toate.randomForestoutput if the selected scoring methods includes'boosting'.ate.poisson: A list of results similar toate.randomForestoutput if the selected scoring methods includes'poisson'.ate.twoReg: A list of results similar toate.randomForestoutput if the selected scoring methods includes'twoReg'.ate.contrastReg: A list of results similar toate.randomForestoutput if the selected scoring methods includes'contrastReg'. This method has an additional element in the list of results:converge.contrastReg.cv: A vector of logical value of lengthcv.n. The ith element indicates whether the algorithm converged in the ith cross-validation iteration.
rd.<method>: Subgroup event risk differences attau0, treatment 1 minus treatment 0, in training and validation sets.overall.rd.trainandoverall.rd.validcontain the corresponding overall differences. These estimates use the same censoring assumptions as the cumulative hazard ratio.chr.<method>: A list of subgroup marginal cumulative hazard ratios attau0, with training and validation matrices for high, low and disjoint groups. Matrix names use the prefixchr.est.; undefined estimates areNA.overall.chr.trainandoverall.chr.validcontain the corresponding overall fold estimates. Existinghr.*results are conditional Cox HRs.hr.randomForest: A list of adjusted hazard ratio if the selected scoring methods includes'randomForest':hr.est.train.high.cv: A matrix of numerical values withlength(prop.cutoff)rows andcv.ncolumns. The ith column/jth row cell contains the estimated HR in the nested subgroup of high responders defined by CATE score above (ifhigher.y = FALSE) or below (ifhigher.y = TRUE) theprop.cutoff[j]x100% percentile of the estimated CATE score in the training set in the ith cross-validation iteration.hr.est.train.low.cv: A matrix of numerical values withlength(prop.cutoff) - 1rows andcv.ncolumns. TThe ith column/jth row cell contains the estimated HR in the nested subgroup of low responders defined by CATE score below (ifhigher.y = FALSE) or above (ifhigher.y = TRUE) theprop.cutoff[j]x100% percentile of the estimated CATE score in the training set in the ith cross-validation iteration.hr.est.valid.high.cv: Same ashr.est.train.high.cv, but in the validation set.hr.est.valid.low.cv: Same ashr.est.train.low.cv, but in the validation set.hr.est.train.group.cv: A matrix of numerical values withlength(prop.multi) - 1rows andcv.ncolumns. The ith column contains the estimated HR inlength(prop.multi) - 1mutually exclusive subgroups defined byprop.multiin the training set in ith cross-validation iteration.hr.est.valid.group.cv: Same ashr.est.train.group.cv, but in the validation set.
hr.boosting: A list of results similar tohr.randomForestoutput if the selected scoring methods includes'boosting'.hr.poisson: A list of results similar tohr.randomForestoutput if the selected scoring methods includes'poisson'.hr.twoReg: A list of results similar tohr.randomForestoutput if the selected scoring methods includes'twoReg'.hr.contrastReg: A list of results similar tohr.randomForestoutput if the selected scoring methods includes'contrastReg'.props: A list of 3 elements:prop.onlyhigh: The original argumentprop.cutoff, reformatted as necessary.prop.bi: The original argumentprop.cutoff, similar toprop.onlyhighbut reformatted to exclude 1.prop.multi: The original argumentprop.multi, reformatted as necessary to include 0 and 1.
overall.ate.train: A vector of numerical values of lengthcv.n. The ith element contains the ATE (RMTL ratio) in the training set of the ith cross-validation iteration, estimated with the doubly robust estimator.overall.hr.train: A vector of numerical values of lengthcv.n. The ith element contains the ATE (HR) in the training set of the ith cross-validation iteration.overall.ate.valid: A vector of numerical values of lengthcv.n. The ith element contains the ATE (RMTL ratio) in the validation set of the ith cross-validation iteration, estimated with the doubly robust estimator.overall.hr.valid: A vector of numerical values of lengthcv.n. The ith element contains the ATE (HR) in the validation set of the ith cross-validation iteration.errors/warnings: A nested list of errors and warnings that were wrapped during the calculation of ATE. Errors and warnings are organized by scoring method and position in the CV flow.higher.y: The originalhigher.yargument.abc: The originalabcargument.cv.n: The originalcv.nargument.response: The type of response. Always 'survival' for this function.formulas:A list of 3 elements: (1)outcome_modelargument, (2)ps_modelargument and (3) original labels of the left-hand side variable inps_model(treatment) if it was not 0/1.
Details
The CATE score represents an individual-level treatment effect expressed as the restricted mean survival time (RMTL) ratio) for survival outcomes. It can be estimated with boosting, Poisson regression, random forest, and the doubly robust estimator two regressions (Yadlowsky, 2020) applied separately by treatment group or with the other doubly robust estimator contrast regression (Yadlowsky, 2020) applied to the entire data set.
Internal CV is applied to reduce optimism in choosing the CATE estimation method that
captures the most treatment effect heterogeneity. The CV is applied by repeating the
following steps cv.n times:
Split the data into a training and validation set according to
train.prop. The training and validation sets must be balanced with respect to covariate distributions and doubly robust RMTL ratio estimates (seeerror.max).Estimate the CATE score in the training set with the specified scoring method.
Predict the CATE score in the validation set using the scoring model fitted from the training set.
Build nested subgroups of treatment responders in the training and validation sets, separately, and estimate the ATE within each nested subgroup. For each element i of
prop.cutoff(e.g.,prop.cutoff[i]= 0.6), take the following steps:Identify high responders as observations with the 60% (i.e.,
prop.cutoff[i]x100%) highest (ifhigher.y = FALSE) or lowest (ifhigher.y = TRUE) estimated CATE scores.Estimate the ATE in the subgroup of high responders using a doubly robust estimator.
Conversely, identify low responders as observations with the 40% (i.e., 1 -
prop.cutoff[i]x100%) lowest (ifhigher.y= FALSE) or highest (ifhigher.y= TRUE) estimated CATE scores.Estimate the ATE in the subgroup of low responders using a doubly robust estimator.
If
abc= TRUE, calculate the area between the ATE and the series of ATEs in nested subgroups of high responders in the validation set.Build mutually exclusive subgroups of treatment responders in the training and validation sets, separately, and estimate the ATE within each subgroup. Mutually exclusive subgroups are built by splitting the estimated CATE scores according to
prop.multi.
References
Yadlowsky, S., Pellegrini, F., Lionetto, F., Braune, S., & Tian, L. (2020). Estimation and validation of ratio-based conditional average treatment effects using observational data. Journal of the American Statistical Association, 1-18.. DOI: 10.1080/01621459.2020.1772080.
See also
catefitsurv() function and boxplot(), abc methods for
"precmed" objects.
Examples
# \donttest{
library(survival)
tau0 <- with(survivalExample,
min(quantile(y[trt == "drug1"], 0.95), quantile(y[trt == "drug0"], 0.95)))
catecv <- catecvsurv(data = survivalExample,
outcome_method = "poisson",
outcome_model = Surv(y, d) ~ age + female + previous_cost +
previous_number_relapses,
ps_model = trt ~ age + previous_treatment,
censoring_model = ~ age + previous_cost + previous_treatment,
tau0 = tau0,
higher.y = TRUE,
cv.n = 5, seed = 999, verbose = 1)
#> Variable trt was recoded to 0/1 with drug0->0 and drug1->1.
#>
|
| | 0%
#> cv = 1
#> splitting the data..
#> training..
#> validating..
#> Fri Nov 20 21:46:51 2026
#>
|
|============== | 20%
#> cv = 2
#> splitting the data..
#> training..
#> validating..
#> Fri Nov 20 21:46:55 2026
#>
|
|============================ | 40%
#> cv = 3
#> splitting the data..
#> training..
#> validating..
#> Fri Nov 20 21:46:58 2026
#>
|
|========================================== | 60%
#> cv = 4
#> splitting the data..
#> training..
#> validating..
#> Fri Nov 20 21:47:01 2026
#>
|
|======================================================== | 80%
#> cv = 5
#> splitting the data..
#> training..
#> validating..
#> Fri Nov 20 21:47:05 2026
#>
|
|======================================================================| 100%
#> Total runtime : 16.61 secs
# Try:
plot(catecv, ylab = "RMTL ratio of drug1 vs drug0 in each subgroup")
boxplot(catecv, ylab = "RMTL ratio of drug1 vs drug0 in each subgroup")
#> Warning: Removed 4 rows containing non-finite outside the scale range
#> (`stat_boxplot()`).
abc(catecv)
#> cv1 cv2 cv3 cv4 cv5
#> poisson 0.2165482 0.1988858 0.2184554 0.2111615 0.09635128
# }
