Reading Data into R and importing packages:

library(survival)
library(flexsurv)
## Warning: package 'flexsurv' was built under R version 4.0.3
dataa=read.csv("C:/Users/Prokarso/Documents/Book2.csv")
dataa

Creating Survival Objects:

attach(dataa)

surv_pm=Surv(time=Time[which(Group=="Placebo" & Gender=="Male")],event=Status[which(Group=="Placebo" & Gender=="Male")],type="right")
surv_pf=Surv(time=Time[which(Group=="Placebo" & Gender=="Female")],event=Status[which(Group=="Placebo" & Gender=="Female")],type="right")
surv_tm=Surv(time=Time[which(Group=="Treatment" & Gender=="Male")],event=Status[which(Group=="Treatment" & Gender=="Male")],type="right")
surv_tf=Surv(time=Time[which(Group=="Treatment" & Gender=="Female")],event=Status[which(Group=="Treatment" & Gender=="Female")],type="right")

Creating seperate survival objects for the 4 groups, and fitting the survival curves:

s1=survfit(surv_pm~1,type="kaplan-meier")
summary(s1)
## Call: survfit(formula = surv_pm ~ 1, type = "kaplan-meier")
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##   2.6     11       1    0.909  0.0867       0.7541        1.000
##   5.3     10       1    0.818  0.1163       0.6192        1.000
##   5.7      9       1    0.727  0.1343       0.5064        1.000
##   6.6      8       1    0.636  0.1450       0.4071        0.995
##   8.7      7       1    0.545  0.1501       0.3180        0.936
##   9.2      6       1    0.455  0.1501       0.2379        0.868
##  10.0      4       1    0.341  0.1495       0.1443        0.805
##  11.7      2       1    0.170  0.1418       0.0334        0.871
plot(s1,col = "red",xlab="Time",ylab="S(t)",main="Survival Curve using KM Estimator for Group=Placebo, Gender=Male",cex.main=1.1)

s2=survfit(surv_pf~1,type="kaplan-meier")
summary(s2)
## Call: survfit(formula = surv_pf ~ 1, type = "kaplan-meier")
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##   2.2      9       1    0.889   0.105       0.7056        1.000
##   5.4      8       1    0.778   0.139       0.5485        1.000
##   8.2      7       1    0.667   0.157       0.4200        1.000
##   9.8      6       1    0.556   0.166       0.3097        0.997
##  10.2      5       1    0.444   0.166       0.2141        0.923
##  11.0      4       1    0.333   0.157       0.1323        0.840
##  11.1      3       1    0.222   0.139       0.0655        0.754
plot(s2,col="blue",xlab="Time",ylab="S(t)",main="Survival Curve using KM Estimator for Group=Placebo, Gender=Female",cex.main=1.1)

s3=survfit(surv_tm~1,type="kaplan-meier")
summary(s2)
## Call: survfit(formula = surv_pf ~ 1, type = "kaplan-meier")
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##   2.2      9       1    0.889   0.105       0.7056        1.000
##   5.4      8       1    0.778   0.139       0.5485        1.000
##   8.2      7       1    0.667   0.157       0.4200        1.000
##   9.8      6       1    0.556   0.166       0.3097        0.997
##  10.2      5       1    0.444   0.166       0.2141        0.923
##  11.0      4       1    0.333   0.157       0.1323        0.840
##  11.1      3       1    0.222   0.139       0.0655        0.754
plot(s2,col="brown",xlab="Time",ylab="S(t)",main="Survival Curve using KM Estimator for Group=Treatment, Gender=Male",cex.main=1.1)

s4=survfit(surv_tf~1,type="kaplan-meier")
summary(s2)
## Call: survfit(formula = surv_pf ~ 1, type = "kaplan-meier")
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##   2.2      9       1    0.889   0.105       0.7056        1.000
##   5.4      8       1    0.778   0.139       0.5485        1.000
##   8.2      7       1    0.667   0.157       0.4200        1.000
##   9.8      6       1    0.556   0.166       0.3097        0.997
##  10.2      5       1    0.444   0.166       0.2141        0.923
##  11.0      4       1    0.333   0.157       0.1323        0.840
##  11.1      3       1    0.222   0.139       0.0655        0.754
plot(s2,col="purple",xlab="Time",ylab="S(t)",main="Survival Curve using KM Estimator for Group=Treatment, Gender=Female",cex.main=1.1)

Checking whether there is significant difference between the four survival functions:

Ho: There is no significant difference vs H1: There is significant difference

s0=Surv(time=Time,event=Status,type="right")
survdiff(s0~Group+Gender)
## Call:
## survdiff(formula = s0 ~ Group + Gender)
## 
##                                 N Observed Expected (O-E)^2/E (O-E)^2/V
## Group=Placebo, Gender=Female    9        7    10.07     0.935     1.564
## Group=Placebo, Gender=Male     11        8    10.23     0.486     0.767
## Group=Treatment, Gender=Female 10        7     3.18     4.602     5.711
## Group=Treatment, Gender=Male   11        7     5.52     0.394     0.523
## 
##  Chisq= 7.6  on 3 degrees of freedom, p= 0.05

Since p value=0.05, we reject Ho in favor of H1 , and conclude that there is significant difference between the four groups.

Checking whether there is significant difference between placebo and treatment:

Ho: There is no significant difference vs H1: There is significant difference

survdiff(s0~Group)
## Call:
## survdiff(formula = s0 ~ Group)
## 
##                  N Observed Expected (O-E)^2/E (O-E)^2/V
## Group=Placebo   20       15     20.3      1.38       5.5
## Group=Treatment 21       14      8.7      3.23       5.5
## 
##  Chisq= 5.5  on 1 degrees of freedom, p= 0.02

Since p value=0.02, we reject Ho in favor of H1 , and conclude that there is significant difference between the two groups.