data(mypbc)
pbc<-mypbc
pbc$time<-pbc$time+runif(418)*0.1; pbc$time<-pbc$time/365
pbc<-subset(pbc,complete.cases(pbc));
covs<-as.matrix(pbc[,-c(1:3,6)])
covs<-cbind(covs[,c(1:6,16)],log(covs[,7:15]))
covs<-scale(covs);
### 5 PLS components for the 16 covariates
### based on Gui-Li approach with constant effects
out<-additive.pls(Surv(time,status>=1)~covs,pbc,max.time=7,pls.dim=5)
### survival predictions
par(mfrow=c(1,3))
pout=predict.pls(out,Z=covs)
matplot(pout$times,t(pout$surv[1:20,]),type="l",ylim=c(0,1),xlab="time",ylab="survival")
### cross-validated number of pls components
outcv<-pls.surv.cv(Surv(time,status>=1)~covs,pbc,max.time=7,pls.dims=0:2)
plot(outcv$pls.dims,outcv$cv,type="l")
out2<-additive.pls(Surv(time,status>=1)~covs,pbc,max.time=7,
pls.dim=outcv$cv.dim)
pout=predict.pls(out2, Z= covs)
matplot(pout$times,t(pout$surv[1:20,]),type="l",ylim=c(0,1),
xlab="time",ylab="survival")
### 2 PLS components for the 3 covariates
### age and sex are fixed covariates
data(sTRACE)
out<-additive.pls(Surv(time,status==9)~const(age)+const(sex)+
vf+diabetes+chf,sTRACE,max.time=7,pls.dim=2,silent=1)Run the code above in your browser using DataLab