# Example with cross validation and unemployment data
library(Ecdat)
library(caret)
data(UnempDur)
# Extract subset of data
set.seed(635)
IDsample <- sample(1:dim(UnempDur)[1], 100)
UnempDurSubset <- UnempDur [IDsample, ]
head(UnempDurSubset)
range(UnempDurSubset$spell)
set.seed(7550)
CVfolds <- createFolds (y=UnempDurSubset$spell, returnTrain=TRUE, k=2)
# Estimate true positive rate of time interval 7:
# Correspondes to three and a half month duration (each interval is of length two weeks)
tryTPR <- tprUno (timepoint=7, dataSet=UnempDurSubset, trainIndices=CVfolds,
survModelFormula=spell ~ age + logwage, censModelFormula=censor1 ~ 1,
linkFunc="logit", idColumn=NULL)
tryTPR
plot(tryTPR)
# Estimate false positive rate of time interval 7:
tryFPR <- fprUno (timepoint=7, dataSet=UnempDurSubset, trainIndices=CVfolds,
survModelFormula=spell ~ age + logwage, censModelFormula=censor1 ~ 1,
linkFunc="logit", idColumn=NULL)
tryFPR
plot(tryFPR)
# Estimate false positive rate of time interval 7:
tryAUC <- aucUno (tprObj=tryTPR, fprObj=tryFPR)
tryAUC
plot(tryAUC)
# Estimate global concordance index:
tryConcorIndex <- concorIndex (tryAUC)
tryConcorIndex
summary(tryConcorIndex)
Run the code above in your browser using DataLab