forked from maryamsadeghimehr/HCV_Modelling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenario_treatFg.R
72 lines (58 loc) · 2.09 KB
/
scenario_treatFg.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Treat_scenario <- 1
if (Treat_scenario == 1)
{
#########treatment uptake
# In this scenario individuals will be treated if they are in 2014 or more, and they have fibrosis F2 or more,
# also if they have fibrosis less than F2, they will be treated if they are in 2018 or more.
treat.fun <- function(bl, history)
{
source("index_block_fs_stage.r")
lr = 0
index = stage_identifier(lr , bl, history)
index_fs = index[2]
state = index[3]
if (is.element(state, c(31:36)) )
index_fs = 6 # DC
if (is.element(state, c(37:42)) )
index_fs = 7 # HCC
if (is.element(state, c(43:48)) )
index_fs = 8 #LT
#############################################
Year_infection = bl[ "BirthYear"] + bl["Age"]
epsi = runif(1, 0, 1)
res <- ifelse(index_fs >= 3, (2014 - (sum(history) + Year_infection)),
(2018 - (sum(history) + Year_infection))) # treat in F2 or above
epsi = ifelse(sum(history) + Year_infection < 2014, runif(1,0,5) , epsi)
res <- max(0, res) + epsi
return(res)
}
}
if (Treat_scenario == 2)
{
#########treatment uptake
# In this scenario individuals will be treated if they are in 2014 or more, and they have fibrosis F2 or more,
# also if they have fibrosis less than F2, they will be treated if they are in 2018 or more.
treat.fun <- function(bl, history)
{
source("index_block_fs_stage.r")
lr = 0
index = stage_identifier(lr , bl, history)
index_fs = index[2]
state = index[3]
if (is.element(state, c(31:36)) )
index_fs = 6 # DC
if (is.element(state, c(37:42)) )
index_fs = 7 # HCC
if (is.element(state, c(43:48)) )
index_fs = 8 #LT
#############################################
Year_infection = bl[ "BirthYear"] + bl["Age"]
# epsi = runif(1, 0, 1)
epsi = ((sum(history) + Year_infection) - 2014) / (1 + (sum(history) + Year_infection - 2014))
res <- ifelse(index_fs >= 3, (2014 - (sum(history) + Year_infection)),
(2018 - (sum(history) + Year_infection))) # treat in F2 or above
epsi = ifelse(sum(history) + Year_infection < 2014, runif(1,0,5) , epsi)
res <- max(0, res) + epsi
return(res)
}
}