## Not run:
# ################################################################################
# # Load one of the following two data sets
# ################################################################################
#
# # breast cancer data
# data(bcos) ## load bcos and bcos.grid
# mydata <- bcos
# mygrid <- bcos.grid
# myformula <- Surv(left, right, type="interval2") ~ trt
#
# # tooth data
# # data(tooth) ## load tooth and tooth.grid
# # mydata <- tooth
# # mygrid <- tooth.grid
# # myformula <- Surv(left, right, type="interval2") ~ dmf + sex
#
# ################################################################################
# # Fit Bayesian Cox models
# ################################################################################
#
# # Fit time-independent coefficient model
# fit0 <- bayesCox(myformula, mydata, mygrid, out="tiCox.txt",
# model="TimeIndep",
# base.prior=list(type="Gamma", shape=0.1, rate=0.1),
# coef.prior=list(type="Normal", mean=0, sd=1),
# gibbs=list(iter=100, burn=20, thin=1, verbose=TRUE, nReport=5))
# plotCoef(coef(fit0))
#
# # Fit time-varying coefficient model
# fit1 <- bayesCox(myformula, mydata, mygrid, out="tvCox.txt",
# model="TimeVarying",
# base.prior=list(type="Gamma", shape=0.1, rate=0.1),
# coef.prior=list(type="AR1", sd=1),
# gibbs=list(iter=100, burn=20, thin=1, verbose=TRUE, nReport=5))
# plotCoef(coef(fit1))
#
# # Fit dynamic coefficient model with time-varying baseline hazards
# fit2 <- bayesCox(myformula, mydata, mygrid, out="dynCox1.txt",
# model="Dynamic",
# base.prior=list(type="Gamma", shape=0.1, rate=0.1),
# coef.prior=list(type="HAR1", shape=2, scale=1),
# gibbs=list(iter=100, burn=20, thin=1, verbose=TRUE, nReport=5))
# plotCoef(coef(fit2))
# plotJumpTrace(jump(fit2))
# plotJumpHist(jump(fit2))
# plotNu(nu(fit2))
#
# # Plot the coefficient estimates from three models together
# plotCoef(rbind(coef(fit0), coef(fit1), coef(fit2)))
#
# # Fit dynamic coefficient model with dynamic hazards (in log scales)
# fit3 <- bayesCox(myformula, mydata, mygrid, out="dynCox2.txt",
# model="Dynamic",
# base.prior=list(type="Const"),
# coef.prior=list(type="HAR1", shape=2, scale=1),
# gibbs=list(iter=100, burn=20, thin=1, verbose=TRUE, nReport=5),
# control=list(intercept=TRUE))
# plotCoef(coef(fit3))
# plotJumpTrace(jump(fit3))
# plotJumpHist(jump(fit3))
# plotNu(nu(fit3))
# ## End(Not run)
Run the code above in your browser using DataLab