#Program to analyze the data in Table 12.4
library(survival)
yd=read.table("C:\\Research\\Book\\Data\\table124.txt")
subject = yd[,1]
days = yd[,2]
status = yd[,3]
no=length(subject)
censor=rep(0,no)
for (i in 1:no) {if (status[i]>=2) censor[i]=1}
#yy=cbind(subject,days,status,censor)
#yy

#Survival Analysis
sm1 = Surv(days, status==1)~1
syy = survfit(sm1)
syy
summary(syy, censored=T)
plot(syy)

#######################################################################

#Program to analyze the data in Table 12.5
library(survival)
library(coin)
yd=read.table("C:\\Research\\Book\\Data\\table125.txt")
subject = yd[,1]
time = yd[,2]
status = yd[,3]
no=length(subject)
group=rep(1,no)
for (i in 1:no) {if (subject[i]>=37) group[i]=2}
group=factor(group)

#Survival Analysis
sm1 = Surv(time, status==1)~group
sy1 = survfit(sm1)
sy1
summary(sy1)
plot(sy1)
survdiff(sm1)
surv_test(sm1, distribution="exact")

#One can include the censored observations by the following command
#summary(sy1, censored=T)

#One can include the confidence interval by the following command
#plot(sy1, conf.int=T, col=c("black","red"))

#######################################################################

#Program to analyze the data in Table 12.5
library(survival)
library(coin)
yd=read.table("C:\\Research\\Book\\Data\\table125.txt")
subject = yd[,1]
time = yd[,2]
status = yd[,3]
no=length(subject)
group=rep(1,no)
for (i in 1:no) {if (subject[i]>=37) group[i]=2}
group=factor(group)

#Survival Analysis
sm1 = Surv(time, status==1)~group
sy1 = survfit(sm1)
sy1
summary(sy1)
plot(sy1)
survdiff(sm1)
surv_test(sm1, distribution="exact")

#One can include the censored observations by the following command
#summary(sy1, censored=T)

#One can include the confidence interval by the following command
#plot(sy1, conf.int=T, col=c("black","red"))









