pec {pec} | R Documentation |
Prediction error curves
Description
Evaluating the performance of risk prediction models in survival analysis. The Brier score is a weighted average of the squared distances between the observed survival status and the predicted survival probability of a model. Roughly the weights correspond to the probabilities of not being censored. The weights can be estimated depend on covariates. Prediction error curves are obtained when the Brier score is followed over time. Cross-validation based on bootstrap resampling or bootstrap subsampling can be applied to assess and compare the predictive power of various regression modelling strategies on the same set of data.
Usage
pec(
object,
formula,
data,
traindata,
times,
cause,
start,
maxtime,
exact = TRUE,
exactness = 100,
fillChar = NA,
cens.model = "cox",
ipcw.refit = FALSE,
ipcw.args = NULL,
splitMethod = "none",
B,
M,
reference = TRUE,
model.args = NULL,
model.parms = NULL,
keep.index = FALSE,
keep.matrix = FALSE,
keep.models = FALSE,
keep.residuals = FALSE,
keep.pvalues = FALSE,
noinf.permute = FALSE,
multiSplitTest = FALSE,
testIBS,
testTimes,
confInt = FALSE,
confLevel = 0.95,
verbose = TRUE,
savePath = NULL,
slaveseed = NULL,
na.action = na.fail,
...
)
Arguments
object |
A named list of prediction models, where allowed entries are
(1) R-objects for which a predictSurvProb method exists (see
details), (2) a |
formula |
A survival formula as obtained either
with |
data |
A data frame in which to validate the prediction models and to
fit the censoring model. If |
traindata |
A data frame in which the models are trained. This argument is used only in the absence of crossvalidation, in which case it is passed to the predictHandler function predictSurvProb |
times |
A vector of time points. At each time point the prediction
error curves are estimated. If |
cause |
For competing risks, the event of interest. Defaults to the
first state of the response, which is obtained by evaluating the left hand
side of |
start |
Minimal time for estimating the prediction error curves. If
missing and |
maxtime |
Maximal time for estimating the prediction error curves. If missing the largest value of the response variable is used. |
exact |
Logical. If |
exactness |
An integer that determines how many equidistant gridpoints
are used between |
fillChar |
Symbol used to fill-in places where the values of the
prediction error curves are not available. The default is |
cens.model |
Method for estimating inverse probability of censoring weigths:
|
ipcw.refit |
If |
ipcw.args |
List of arguments passed to function specified by argument |
splitMethod |
SplitMethod for estimating the prediction error curves.
The random splitting is repeated
|
B |
Number of bootstrap samples. The default depends on argument
|
M |
The size of the bootstrap samples for resampling without replacement. Ignored for resampling with replacement. |
reference |
Logical. If |
model.args |
List of extra arguments that can be passed to the
|
model.parms |
Experimental. List of with exactly one entry for each
entry in |
keep.index |
Logical. If |
keep.matrix |
Logical. If |
keep.models |
Logical. If |
keep.residuals |
Logical. If |
keep.pvalues |
For |
noinf.permute |
If |
multiSplitTest |
If |
testIBS |
A range of time points for testing differences between models in the integrated Brier scores. |
testTimes |
A vector of time points for testing differences between models in the time-point specific Brier scores. |
confInt |
Experimental. |
confLevel |
Experimental. |
verbose |
if |
savePath |
Place in your file system (i.e., a directory on your
computer) where training models fitted during cross-validation are saved. If
|
slaveseed |
Vector of seeds, as long as |
na.action |
Passed immediately to model.frame. Defaults to na.fail. If set otherwise most prediction models will not work. |
... |
Not used. |
Details
Note that package riskRegression provides very similar functionality (and much more) but not yet every feature of pec.
Missing data in the response or in the input matrix cause a failure.
The status of the continuous response variable at cutpoints (times
),
ie status=1 if the response value exceeds the cutpoint and status=0
otherwise, is compared to predicted event status probabilities which are
provided by the prediction models on the basis of covariates. The
comparison is done with the Brier score: the quadratic difference between
0-1 response status and predicted probability.
There are two different sources for bias when estimating prediction error in
right censored survival problems: censoring and high flexibility of the
prediction model. The first is controlled by inverse probability of
censoring weighting, the second can be controlled by special Monte Carlo
simulation. In each step, the resampling procedures reevaluate the
prediction model. Technically this is done by replacing the argument
object$call$data
by the current subset or bootstrap sample of the
full data.
For each prediction model there must be a predictSurvProb
method: for
example, to assess a prediction model which evaluates to a myclass
object one defines a function called predictSurvProb.myclass
with
arguments object,newdata,cutpoints,...
Such a function takes the object and derives a matrix with predicted event status probabilities for each subject in newdata (rows) and each cutpoint (column) of the response variable that defines an event status.
Currently, predictSurvProb
methods are readily available for
various survival models, see methods(predictSurvProb)
Value
A pec
object. See also the help pages of the corresponding
print
, summary
, and plot
methods. The object includes
the following components:
PredErr |
The estimated prediction error
according to the |
AppErr |
The training error or apparent error obtained when the
model(s) are evaluated in the same data where they were trained. Only if
|
BootCvErr |
The prediction error when the model(s)
are trained in the bootstrap sample and evaluated in the data that are not
in the bootstrap sample. Only if |
NoInfErr |
The prediction
error when the model(s) are evaluated in the permuted data. Only if
|
weight |
The weight used to linear combine the
|
overfit |
Estimated |
call |
The call that produced the object |
time |
The time points at which the prediction error curves change. |
ipcw.fit |
The fitted censoring model that was used for re-weighting the Brier score residuals. See Gerds and Schumacher (2006, Biometrical Journal) |
n.risk |
The number of subjects at risk for all time points. |
models |
The prediction models fitted in their own data. |
cens.model |
The censoring models. |
maxtime |
The latest timepoint where the prediction error curves are estimated. |
start |
The earliest timepoint where the prediction error curves are estimated. |
exact |
|
splitMethod |
The splitMethod used for estimation of the overfitting bias. |
Author(s)
Thomas Alexander Gerds tag@biostat.ku.dk
References
Gerds TA, Kattan MW. Medical Risk Prediction Models: With Ties to Machine Learning. Chapman and Hall/CRC https://www.routledge.com/9781138384477
Ulla B. Mogensen, Hemant Ishwaran, Thomas A. Gerds (2012). Evaluating Random Forests for Survival Analysis Using Prediction Error Curves. Journal of Statistical Software, 50(11), 1-23. DOI 10.18637/jss.v050.i11
E. Graf et al. (1999), Assessment and comparison of prognostic classification schemes for survival data. Statistics in Medicine, vol 18, pp= 2529–2545.
Efron, Tibshirani (1997) Journal of the American Statistical Association 92, 548–560 Improvement On Cross-Validation: The .632+ Bootstrap Method.
Gerds, Schumacher (2006), Consistent estimation of the expected Brier score in general survival models with right-censored event times. Biometrical Journal, vol 48, 1029–1040.
Thomas A. Gerds, Martin Schumacher (2007) Efron-Type Measures of Prediction Error for Survival Analysis Biometrics, 63(4), 1283–1287 doi:10.1111/j.1541-0420.2007.00832.x
Martin Schumacher, Harald Binder, and Thomas Gerds. Assessment of survival prediction models based on microarray data. Bioinformatics, 23(14):1768-74, 2007.
Mark A. van de Wiel, Johannes Berkhof, and Wessel N. van Wieringen Testing the prediction error difference between 2 predictors Biostatistics (2009) 10(3): 550-560 doi:10.1093/biostatistics/kxp011
See Also
plot.pec
, summary.pec
,
R2
, crps
Examples
# simulate an artificial data frame
# with survival response and two predictors
set.seed(130971)
library(prodlim)
library(survival)
dat <- SimSurv(100)
# fit some candidate Cox models and compute the Kaplan-Meier estimate
Models <- list("Cox.X1"=coxph(Surv(time,status)~X1,data=dat,x=TRUE,y=TRUE),
"Cox.X2"=coxph(Surv(time,status)~X2,data=dat,x=TRUE,y=TRUE),
"Cox.X1.X2"=coxph(Surv(time,status)~X1+X2,data=dat,x=TRUE,y=TRUE))
# compute the apparent prediction error
PredError <- pec(object=Models,
formula=Surv(time,status)~X1+X2,
data=dat,
exact=TRUE,
cens.model="marginal",
splitMethod="none",
B=0,
verbose=TRUE)
print(PredError,times=seq(5,30,5))
summary(PredError)
plot(PredError,xlim=c(0,30))
# Comparison of Weibull model and Cox model
library(survival)
library(rms)
library(pec)
data(pbc)
pbc <- pbc[sample(1:NROW(pbc),size=100),]
f1 <- psm(Surv(time,status!=0)~edema+log(bili)+age+sex+albumin,data=pbc)
f2 <- coxph(Surv(time,status!=0)~edema+log(bili)+age+sex+albumin,data=pbc,x=TRUE,y=TRUE)
f3 <- cph(Surv(time,status!=0)~edema+log(bili)+age+sex+albumin,data=pbc,surv=TRUE)
brier <- pec(list("Weibull"=f1,"CoxPH"=f2,"CPH"=f3),data=pbc,formula=Surv(time,status!=0)~1)
print(brier)
plot(brier)
# compute the .632+ estimate of the generalization error
set.seed(130971)
library(prodlim)
library(survival)
dat <- SimSurv(100)
set.seed(17100)
PredError.632plus <- pec(object=Models,
formula=Surv(time,status)~X1+X2,
data=dat,
exact=TRUE,
cens.model="marginal",
splitMethod="Boot632plus",
B=3,
verbose=TRUE)
print(PredError.632plus,times=seq(4,12,4))
summary(PredError.632plus)
plot(PredError.632plus,xlim=c(0,30))
# do the same again but now in parallel
## Not run: set.seed(17100)
# library(doMC)
# registerDoMC()
PredError.632plus <- pec(object=Models,
formula=Surv(time,status)~X1+X2,
data=dat,
exact=TRUE,
cens.model="marginal",
splitMethod="Boot632plus",
B=3,
verbose=TRUE)
## End(Not run)
# assessing parametric survival models in learn/validation setting
learndat <- SimSurv(50)
testdat <- SimSurv(30)
library(survival)
library(rms)
f1 <- psm(Surv(time,status)~X1+X2,data=learndat)
f2 <- psm(Surv(time,status)~X1,data=learndat)
pf <- pec(list(f1,f2),formula=Surv(time,status)~1,data=testdat,maxtime=200)
plot(pf)
summary(pf)
# ---------------- competing risks -----------------
library(survival)
library(riskRegression)
if(requireNamespace("cmprsk",quietly=TRUE)){
library(cmprsk)
library(pec)
cdat <- SimCompRisk(100)
f1 <- CSC(Hist(time,event)~X1+X2,cause=2,data=cdat)
f2 <- CSC(Hist(time,event)~X1,data=cdat,cause=2)
f3 <- FGR(Hist(time,event)~X1+X2,cause=2,data=cdat)
f4 <- FGR(Hist(time,event)~X1+X2,cause=2,data=cdat)
p1 <- pec(list(f1,f2,f3,f4),formula=Hist(time,event)~1,data=cdat,cause=2)
}