# \donttest{
# Generate survival data with five informative covariates for one subgroup
n <- 400; p <- 1000
set.seed(129)
group<-rbinom(n,1,0.5)
x <- matrix(rnorm(n*p,0,1),n,p)
beta.vec1 <- c(c(1,1,1,1,1),rep(0,p-5))
beta.vec0 <- c(c(0,0,0,0,0),rep(0,p-5))
linpred<-ifelse(group==1,x %*% beta.vec1,x %*% beta.vec0)
set.seed(1234)
real.time<- (-(log(runif(n)))/(1/20*exp(linpred)))
cens.time <- rexp(n,rate=1/20)
obs.status <- ifelse(real.time <= cens.time,1,0)
obs.time <- ifelse(real.time <= cens.time,real.time,cens.time)
# Fit a stratified weighted Cox proportional hazards model
# by \code{resample.CoxBoost}
mix.list=c(0.001, 0.01, 0.05, 0.1, 0.25, 0.35, 0.5, 0.7, 0.9, 0.99)
RIF <- resample.CoxBoost(
time=obs.time,status=obs.status,x=x,
# use more repetitions (eg `rep = 100`) for more stable results
rep=5,
maxstepno=200,multicore=FALSE,
mix.list=mix.list,
stratum=group,stratnotinfocus=0,penalty=sum(obs.status)*(1/0.02-1),
criterion="hscore",unpen.index=NULL)
# RIF is a list with number of resampling data sets list objects, each list
# object has further two list objects, the beta coefficients for all
# weights and the selected number of boosting steps.
# For each list object i \code{RIF[[i]]$beta} contains the beta
# coefficients with length mix.list*p for p covariates and with
# \code{RIF[[i]]$CV.opt}
# For getting an insight in the RIF Distribution of different weights
# use the following code:
RIF1<-c()
for (i in 1: length(RIF)){RIF1<-c(RIF1,RIF[[i]][[1]])}
freqmat <-matrix(apply(matrix(unlist(RIF1), ncol=length(RIF))!=0,1,mean),
ncol=length(mix.list))
# freqmat is a matrix with p rows and \code{length(mix.list)} columns
# which contains resampling inclusion frequencies for the different
# covariates and different weights.
# two plotting functions are available for the resulting object:
stabtrajec(RIF)
weightfreqmap(RIF)
# }
Run the code above in your browser using DataLab