## 3-state illness-death multistate model (no left-truncation)
## Row data for 3 individuals
## Data in the form "id", "start", "stop", "start.stage", "end.stage"
p1 <- c(1,0,0.21,1,3)
p2 <- c(2,0,0.799,1,2)
p22 <- c(2,0.799,1.577,2,3)
p3 <- c(3,0,0.199,1,0)
## Combining data into a matrix
ex1 <- rbind(p1,p2,p22,p3)
colnames(ex1) <- c("id", "start", "stop", "start.stage", "end.stage")
ex1 <- data.frame(id=ex1[,1], start=ex1[,2], stop=ex1[,3],
start.stage=ex1[,4], end.stage=ex1[,5])
## Inputting nodes & edges of the tree structure
Nodes <- c("1","2","3") # states in MSM
Edges <- list("1"=list(edges=c("2","3")),"2"=list(edges=c("3")),
"3"=list(edges=NULL)) ## allowed transitions between states
## edges=NULL implies terminal node
## Specifying tree
treeobj <- new("graphNEL", nodes=Nodes, edgeL=Edges,
edgemode="directed")
ans1 <- msSurv(ex1, treeobj)
print(ans1) ## same as 'show(ans1)'
summary(ans1) ## prints IQR for ans1
summary(ans1, all=TRUE) ## prints all event times for ans1
## prints only state occupation probability info for all event times
summary(ans1, all=TRUE, trans.pr=FALSE, dist=FALSE)
plot(ans1) ## plots state occupation probability
plot(ans1, states="1")
plot(ans1, states=c("1", "2"))
plot(ans1, plot.type="transprob") ## plots for transition probability
plot(ans1, plot.type="transprob", trans=c("1 2", "1 3"))
Run the code above in your browser using DataLab