-
Notifications
You must be signed in to change notification settings - Fork 2
/
survcode.R
54 lines (51 loc) · 1.5 KB
/
survcode.R
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
#' utility for survival curve illustration
#' @export
build_simple_survival_curve = function() {
set.seed(1234)
x = rexp(200, .3/12)
library(survival)
sx = Surv(x, rep(1,200))
plot(survfit(sx~1), lwd=2, ylab="Survival probability", xlab="Months from diagnosis",
axes=FALSE, xlim=c(0,168), conf.int=FALSE)
axis(2)
axis(1, at = seq(0,max(x),12L))
}
#' utility for survival curve illustration: median estimate sketch
#' @export
show_median_estimate = function() {
set.seed(1234)
x = rexp(200, .3/12)
library(survival)
sx = Surv(x, rep(1,200))
meddat = median(sx)
plot(survfit(sx~1), lwd=2, ylab="Survival probability", xlab="Months from diagnosis",
axes=FALSE, xlim=c(0,168), conf.int=FALSE)
axis(2)
axis(1, at = seq(0,max(x),12L))
abline(h=.5, lwd=2, lty=3)
arrows(meddat$quantile, .5, meddat$quantile, 0, lwd=2, col="blue")
}
#' utility for survival curve illustration: 5y survprob estimate sketch
#' @export
show_5y_estimate = function() {
set.seed(1234)
x = rexp(200, .3/12)
library(survival)
sx = Surv(x, rep(1,200))
plot(survfit(sx~1), lwd=2, ylab="Survival probability", xlab="Months from diagnosis",
axes=FALSE, xlim=c(0,168), conf.int=FALSE)
axis(2)
axis(1, at = seq(0,max(x),12L))
arrows(60, .22, 0, .22, lwd=2, col="purple")
arrows(60, .0, 60, .22, lwd=2, col="purple")
}
#' utility for survival curve, alternate shape
#' @export
do_new_surv = function() {
set.seed(1234)
z = rgamma(200, 10, .15)
gg = Surv(z, rep(1,200))
plot(survfit(gg~1), conf.int=FALSE, axes=FALSE)
axis(2)
axis(1, at = seq(0,max(z),12L))
}