# NOT RUN {
####################################
# A simulated Data Set
####################################
ind<-rbinom(100,1,0.5)
vsim<-ind*rnorm(100,1,0.25)+(1-ind)*rnorm(100,3,0.25)
x1<-rep(c(0,1),50)
x2<-rnorm(100,0,1)
etasim<-x1+-1*x2
time<-vsim*exp(-etasim)
y<-matrix(-999,nrow=100,ncol=2)
for(i in 1:100){
for(j in 1:15){
if((j-1)<time[i] & time[i]<=j){
y[i,1]<-j-1
y[i,2]<-j
}
}
if(time[i]>15)y[i,1]<-15
}
# Initial state
state <- NULL
# MCMC parameters
nburn<-20000
nsave<-10000
nskip<-10
ndisplay<-100
mcmc <- list(nburn=nburn,nsave=nsave,nskip=nskip,
ndisplay=ndisplay,tune=0.125)
# Prior information
prior <- list(alpha=1,beta0=rep(0,2),Sbeta0=diag(1000,2),
m0=0,s0=1,tau1=0.01,tau2=0.01)
# Fit the model
fit1 <- DPsurvint(y~x1+x2,prior=prior,mcmc=mcmc,
state=state,status=TRUE)
fit1
# Summary with HPD and Credibility intervals
summary(fit1)
summary(fit1,hpd=FALSE)
# Plot model parameters
# (to see the plots gradually set ask=TRUE)
plot(fit1,ask=FALSE)
plot(fit1,ask=FALSE,nfigr=2,nfigc=2)
# Plot an specific model parameter
# (to see the plots gradually set ask=TRUE)
plot(fit1,ask=FALSE,nfigr=1,nfigc=2,param="x1")
plot(fit1,ask=FALSE,nfigr=1,nfigc=2,param="mu")
# Table of Pseudo Contour Probabilities
anova(fit1)
# Predictive information with covariates
npred<-10
xnew<-cbind(rep(1,npred),seq(-1.5,1.5,length=npred))
xnew<-rbind(xnew,cbind(rep(0,npred),seq(-1.5,1.5,length=npred)))
grid<-seq(0.00001,14,0.5)
pred1<-predict(fit1,xnew=xnew,grid=grid)
# Plot Baseline information
plot(pred1,all=FALSE,band=TRUE)
#############################################################
# Time to Cosmetic Deterioration of Breast Cancer Patients
#############################################################
data(deterioration)
attach(deterioration)
y<-cbind(left,right)
# Initial state
state <- NULL
# MCMC parameters
nburn<-20000
nsave<-10000
nskip<-20
ndisplay<-1000
mcmc <- list(nburn=nburn,nsave=nsave,nskip=nskip,
ndisplay=ndisplay,tune=0.25)
# Prior information
prior <- list(alpha=10,beta0=rep(0,1),Sbeta0=diag(100,1),
m0=0,s0=1,tau1=0.01,tau2=0.01)
# Fitting the model
fit2 <- DPsurvint(y~trt,prior=prior,mcmc=mcmc,
state=state,status=TRUE)
fit2
# Summary with HPD and Credibility intervals
summary(fit2)
summary(fit2,hpd=FALSE)
# Plot model parameters
# (to see the plots gradually set ask=TRUE)
plot(fit2)
# Table of Pseudo Contour Probabilities
anova(fit2)
# Predictive information with covariates
xnew<-matrix(c(0,1),nrow=2,ncol=1)
grid<-seq(0.01,70,1)
pred2<-predict(fit2,xnew=xnew,grid=grid)
plot(pred2,all=FALSE,band=TRUE)
# }
Run the code above in your browser using DataLab