-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHIVfuns.R
More file actions
44 lines (40 loc) · 971 Bytes
/
HIVfuns.R
File metadata and controls
44 lines (40 loc) · 971 Bytes
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
# Units are months
# Units of g are 1/month, so Sum{step*g) should be 1
testingFun <- function(maxRate
, hMean=12, hShape=2, hheight=4
, step = 0.25, window=150
){
time <- seq(step, window, by=step)
tHaz0 <- dgamma(time, shape=hShape, scale=hMean/hShape)
tHaz <- hheight*tHaz0/max(tHaz0)
hazRate <- maxRate*(1-exp(-tHaz))
Haz <- step*cumsum(hazRate)
return(data.frame(time
, hazRate
, strength = exp(Haz)
))
}
flatFun <- function(L
, step = 0.25, window=150
){
time <- seq(step, window, by=step)
hazRate <- 0*time
return(data.frame(time
, hazRate
, strength = hazRate+L
))
}
HIVgen <- function(earlyProp
, earlyMean=2.5, earlyShape=3
, lateMean=100, lateShape=2
, step = 0.25, window=150
){
time <- seq(step, window, by=step)
d0 <- (
earlyProp*dgamma(time, shape=earlyShape, scale=earlyMean/earlyShape)
+ (1-earlyProp)*dgamma(time, shape=lateShape, scale=lateMean/lateShape)
)
return(data.frame(time
, density=d0/sum(step*d0)
))
}