# NOT RUN {
library(riskRegression)
library(prodlim)
library(lava)
if (!requireNamespace("cmprsk",quietly=TRUE)){
library(cmprsk)
library(pec)
m <- crModel()
m <- addvar(m,c('X1','X2','X3','X4','X5','X6','X7','X8','X9','X10'))
distribution(m,c("X2","X7","X9")) <- binomial.lvm()
regression(m,eventtime1~X1+X2+X5+X9) <- c(-1,1,0.5,0.8)
set.seed(100)
d <- sim(m,100)
## full formula
ff <- Hist(time, event) ~ X1 + X2 + X3 + X4 +X5 + X6 + X7+ X8 + X9 + X10
# Fit full model with FGR
fg <- FGR(ff,cause=1,data=d)
# Backward selection based on the AIC
sfgAIC <- selectFGR(ff, data=d, rule="AIC", direction="backward")
sfgAIC$fit # Final FGR-model with selected variables
# Risk reclassification plot at time = 4
plot(predictEventProb(fg,times=4,newdata=d),
predictEventProb(sfgAIC,times=4,newdata=d))
# Backward selection based on the BIC, while forcing
# the last two variables (X9 and X10) in the model
sfgBIC <- selectFGR(ff, data=d, rule="BIC", direction="backward",
scope.min=~X9+X10)
## apparent performance
pec(list(full.model=fg,selectedAIC=sfgAIC,selectedBIC=sfgBIC),
formula=Hist(time, event)~1,
data=d)
## bootstrap cross-validation performance
set.seed(7)
pec(list(full.model=fg,selectedAIC=sfgAIC,selectedBIC=sfgBIC),
formula=Hist(time, event)~1,
data=d,
B=5,
splitMethod="bootcv")
}
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab