# Read in Data
library(survival)
anemia <- read.delim("http://myweb.uiowa.edu/pbreheny/data/anemia.txt")
S <- with(anemia, Surv(Time,Status!=0))
fit <- survfit(S~1)



# Kaplan-Meier calculations

table1<- cbind(fit$time[1:5], fit$n.risk[1:5], fit$n.event[1:5], round((fit$n.risk[1:5]-fit$n.event[1:5])/fit$n.risk[1:5],4), round(fit$surv[1:5],4))

colnames(table1)<- c("time", "n(t)", "d(t)", "[n(t)-d(t)]/n(t)", "cumproduct")

table1


# Plot Survival Curve
plot(fit, ylab = "Probability", xlab = "Time")


# Separate curves for each treatment group
fit2 <- with(anemia, survfit(S~Trt))
plot(fit2, ylab = "Overall Survival", xlab = "Time", col =
c("red","blue"))
legend("bottomleft", c("MTX","MTX + CSP"), text.col = c("red","blue"),
bty = "n")


# echo=FALSE
boringTable<-as.data.frame(matrix(data=c("A","B","C","D"),nrow=2,byrow=T),
                           row.names=(c("Reject","Fail to Reject")))
colnames(boringTable)<-c("H0 True","H0 False")
print(boringTable)

