# NOT RUN {
# }
# NOT RUN {
library(OptimalTiming)
##################################
## Example 1: This example shows how to use this package to find
## the optimal timing of new treatment initiation
## read data
data(SimCml)
## fit multistate model with treatment not equals NULL
fit=optim.fit(data=SimCml,
transM=matrix(c(0,1,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0,1,1,1,1,0,0
,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0),7,byrow=TRUE),
nstate=7,state_label=c("diagnose","cp1","ap","cp2","bc","sct","death"),
event_label=c("cp1.s","ap.s","cp2.s","bc.s","sct.s","death.s"),
treatment=c("sct","sct.s"),absorb=c("death","death.s"),
cov=c("age"),cov_value=c(0))
## compare different treatment strategies
sim.MTL(obj=fit,nsim=1000,L=120)
##################################
## Example 2: This example shows how to obtain mean total lifetime
## for a given state
## read data
data(SimCml)
## delete the information of transplant time
data=SimCml[SimCml$sct.s==0,]
del=which(names(SimCml)%in%c("sct","sct.s"))
data=data[,-del]
## fit multistate model with treatment equals NULL
fit=optim.fit(data=data,
transM=matrix(c(0,1,0,0,0,0,0,0,1,0,1,1,0,0,0,1,
1,1,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0),6,byrow=TRUE),
nstate=6,state_label=c("diagnose","cp1","ap","cp2","bc","death"),
absorb=c("death","death.s"),
event_label=c("cp1.s","ap.s","cp2.s","bc.s","death.s"),
cov=c("age"),cov_value=c(0))
## calculate mean total lifetime when the initiate state is cp1 or ap
sim.MTL(obj=fit,state=c(2,3),nsim=1000,L=120)
# }
# NOT RUN {
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab