-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhazard.R
More file actions
48 lines (41 loc) · 1.25 KB
/
hazard.R
File metadata and controls
48 lines (41 loc) · 1.25 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
### Helper function:
### Where _would_ the tests go, assuming you know the sizes and hazards?
placeTests <- function(state, haz){
return(state*(1-exp(-haz)))
}
## Is the base hazard right?
checkTests <- function(base, numTests, state, haz){
return(sum(placeTests(state, base*haz)) - numTests)
}
### Where _do_ the tests go if we calibrate the base hazard
### to get the right number number of tests
assignTests <- function(numTests, state, relHaz, mult=1.1){
hpop <- sum(state[relHaz>0])
stopifnot(numTests<=hpop)
popHaz <- min(relHaz[relHaz>0])
prop <- numTests/hpop
upr <- -mult*log(1-prop)/popHaz
lwr <- 0
uni <- uniroot(checkTests, lower=lwr, upper=upr
, numTests=numTests, state=state, haz=relHaz
)
baseHaz <- uni$root
place <- placeTests(state, baseHaz*relHaz)
# print(numTests/sum(place))
return(numTests*place/sum(place))
}
# numTests = tests_conducted[t_index]
# state = SEIR[t_index, names(relHaz)]
# relHaz = relHaz[t_index,]
#
# assignTests(numTests = tests_conducted[t_index], state = SEIR[t_index, names(relHaz)], relHaz = relHaz[t_index,])
assignTests(
numTests <- 180
, state <- c("a" = 100,"b" = 100)
, relHaz <- c("a" = .000001,"b" = 3)
)
assignTests(
numTests <- 18
, state <- c("a" = 100,"b" = 100)
, relHaz <- c("a" = 1,"b" = 3)
)