-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurvival.R
More file actions
64 lines (56 loc) · 1.51 KB
/
Copy pathsurvival.R
File metadata and controls
64 lines (56 loc) · 1.51 KB
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
Survfun <- function(pmax, young, old, ages){
p <- 1 + 0*ages
if (!is.null(old)) p <- p*exp(-ages/old)
if (!is.null(young)) p <- p*exp(-young/ages)
return(p*pmax/max(p))
}
# We calculate L starting with a 1, and with the same length as p (don't pay attention survivors of the last age class for these pictures)
Lfun <- function(p){
L <- 1
for (i in 1:(length(p)-1)){
L[i+1] <- L[i]*p[i]
}
return(L)
}
annplot <- function(x, p, title=""){
par(cex=1.6)
plot(x, p,
xlab = "Age", ylab="Annual survival", type = "b",
ylim = c(0, max(p)),
main=title
)
}
cumplot <- function(x, L, logscale="y", title=""){
par(cex=1.6)
plot(x, L,
xlab = "Age", ylab="Cumulative survival",
type = "b", log=logscale,
main=title
)
}
triplot <- function (pmax=0.5, young=NULL, old=NULL, ages=1:10,
report="a", title=""){
p <- Survfun(pmax, young, old, ages)
L <- Lfun(p)
data.frame(p=p, L=L)
if((report=="a") | (report == "p")) annplot(ages, p, title=title)
if((report=="a") | (report == "l")) cumplot(ages, L, title=title)
if((report=="a") | (report == "L")) cumplot(ages, L, logscale="", title=title)
}
sadplot <- function(pmax=0.5, young=NULL, old=NULL, ages=1:10, lam=1, lamlabel=NULL){
p <- Survfun(pmax, young, old, ages)
L <- Lfun(p)
sad <- L*lam^(-ages)
sad <- sad/sum(sad)
par(cex=1.2)
barplot(sad, names.arg=ages,
horiz=TRUE,
density=7,
xlab = "Proportion",
ylab = "age",
main="Stable age distribution",
)
if(is.null(lamlabel)){lamlabel <- mtext(paste("lambda =", lam))}
mtext(lamlabel)
}
sadplot()