-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscenario_treatF2.R
26 lines (23 loc) · 1.3 KB
/
scenario_treatF2.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
#########treatment uptake
treat.fun <- function( t, bl, history)
{
#identify the state we are in:
###########################################################
m = gems:::auxcounter(ns) # matrix of all transitions (without the terminal states)
if(all(history == 0)) {index_trans=1} else {index_trans=max( which( history > 0))}
index_state = which(m == index_trans, arr.ind = TRUE)[2] # to get the colum number(arrival state) that corresponds to the last transition
#return in which fibrosis state is a certain state (which level of FIbrosis prog?)
ref1 = cbind(rep(1:blocks_size, blocks_nb), 1:(ns - 22))
ref2 = cbind(c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6), c(31,37,43,32,38,44,33,39,45,34,40,46,35,41,47,36,42,48))
ref0 = rbind(ref1, ref2)
index_fs.fun = function(state, ref=ref0)
{
ref[which(ref[,2] == state, arr.ind = TRUE),1]
}
index_fs=index_fs.fun(state = index_state, ref = ref0)
# print(c("we are now in level/state", index_fs,index_state))
################################################################
res <- rep(0, length(t))
ifelse ((index_fs >= 3 && (bl["BirthYear"] + bl["Age"] + sum(history) + t > 2014)), res <- rep((6 * 4)/52, length(t)), res <- rep(666, length(t))) # 6 month after diagnosis and being eligible for treatment, treatment will start.
return(res)
}