View source: R/DiscSurvEvaluationCR.R
| predErrCurveCompRisks | R Documentation |
Estimates prediction error curves for discrete survival competing risks models
predErrCurveCompRisks(
hazards,
testDataShort,
trainDataShort,
timeColumn,
timeAsFactor = FALSE,
eventColumns,
eventColumnsAsFactor = FALSE,
tmax = NULL
)
## S3 method for class 'discSurvPredErrDiscCompRisks'
plot(x, ...)
hazards |
Predicted hazard rates on the test data with model fitted on training data (class "matrix"). Predictions are stored in the rows and the number of columns equal the number of events. |
testDataShort |
Test data in short format (class "data.frame"). |
trainDataShort |
Train data in short format (class "data.frame"). |
timeColumn |
Character giving the column name of the observed times (class "character"). |
timeAsFactor |
Should the time intervals be coded as factor (class "logical")? Default is FALSE. In the default settings the column is treated as quantitative variable (class "numeric"). |
eventColumns |
Character vector giving the column names of the event indicators without censoring column (class "character"). |
eventColumnsAsFactor |
Should the argument eventColumns be interpreted as column name of a factor variable (class "logical")? Default is FALSE. |
tmax |
Gives the maximum time interval for which prediction errors are calculated (class "integer"). It must not be higher than the maximum observed time in the training data. |
x |
Object of class "discSurvPredErrDiscCompRisks" |
... |
Specification of additional arguments in function |
Calculated prediction errors for each competing event. Array with one matrix per competing event, with the predictions in the rows and the time points in the columns.
Moritz Berger moritz.berger@zi-mannheim.de
heyardValCompRisksdiscSurv
intpredErrCurveCompRisks, predErrCurve
###########################
# Example unemployment data
library(Ecdat)
data(UnempDur)
# Select subsample
selectInd1 <- 1:200
selectInd2 <- 201:400
trainSet <- UnempDur[which(UnempDur$spell %in% (1:10))[selectInd1], ]
testSet <- UnempDur[which(UnempDur$spell %in% (1:10))[selectInd2], ]
# Convert to long format
trainSet_long <- dataLongCompRisks(dataShort=trainSet, timeColumn="spell",
eventColumns=c("censor1", "censor4"), timeAsFactor=TRUE)
tmax <- max(trainSet$spell)
testSet_long <- dataLongCompRisks(dataShort=testSet, timeColumn="spell",
eventColumns=c("censor1", "censor4"), aggTimeFormat = TRUE, lastTheoInt=tmax,
timeAsFactor=TRUE)
# Estimate continuation ratio model with logit link
vglmFit <- VGAM::vglm(formula=cbind(e0, e1, e2) ~ timeInt + age + logwage,
data=trainSet_long, family=VGAM::multinomial(refLevel="e0"))
# Calculate predicted hazards
predHazards <- VGAM::predictvglm(vglmFit, newdata=testSet_long, type="response")
# Compute prediction error
predErrCurveCompRisks0 <- predErrCurveCompRisks(
hazards=predHazards[,-1],
testDataShort=testSet, trainDataShort=trainSet,
timeColumn="spell", eventColumns=c("censor1", "censor4"),
tmax=tmax)
# Graphics
plot(predErrCurveCompRisks0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.