-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSurvival_Analysis.Rmd
71 lines (52 loc) · 1.71 KB
/
Survival_Analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: "Basics of Survival analysis:
the R survival package"
author: "D.-L. Couturier"
date: '`r format(Sys.time(), "Last modified: %d %b %Y")`'
output:
html_document:
theme: united
highlight: tango
code_folding: show
toc: true
toc_depth: 2
toc_float: true
fig_width: 8
fig_height: 6
---
<!--- rmarkdown::render("/Volumes/Files/courses/cruk/SurvivalAnalysis/201907/tex/sc/Survival_Analysis.Rmd") --->
<!--- rmarkdown::render("~/courses/cruk/SurvivalAnalysis/201907/tex/sc/Survival_Analysis.Rmd") --->
```{r message = FALSE, warning = FALSE, echo = FALSE}
# change working directory: should be the directory containg the Markdown files:
#setwd("~/courses/cruk/SurvivalAnalysis/201907/tex/sc/")
#setwd("/Volumes/Files/courses/cruk/SurvivalAnalysis/201907/tex/sc")
```
# Section 0: survival package and 'aml' dataset
```{r message = FALSE, warning = FALSE, echo = TRUE}
library(survival)
aml
```
# Section 1: Kaplan Meier plot
```{r message = FALSE, warning = FALSE, echo = TRUE}
leukemia.surv <- survfit(Surv(time, status) ~ x, data = aml)
plot(leukemia.surv, col=c("red","blue"),
mark.time=TRUE,
conf.int=FALSE,
axes=FALSE)
axis(1,seq(0,200,10))
axis(2,seq(0,1,.1),las=2)
legend("topright", c("Maintenance", "No Maintenance"),lty=c(1,1), col=c("red","blue"))
title("Kaplan-Meier Curves\nfor AML Maintenance Study")
#
abline(h=0.5,lty=2)
```
# Section 2: Log-rank test
```{r message = FALSE, warning = FALSE, echo = TRUE}
survdiff(Surv(time, status) ~ x, data = aml)
```
# Section 3: Cox model
```{r message = FALSE, warning = FALSE, echo = TRUE}
# Fit a stratified model
fit = coxph(Surv(time, status) ~ x,data=aml)
summary(fit)
```