-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheligible.R
More file actions
44 lines (39 loc) · 1.03 KB
/
Copy patheligible.R
File metadata and controls
44 lines (39 loc) · 1.03 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
# library(dplyr)
### Eligible or not
combineInfo <- function(test1, test2){
if(!is.na(test1)) return(test1)
return(test2)
}
year <- 365.25
c_visits <- (c_visits
%>% mutate(ageDays=as.numeric(visitdate - dateofbirth))
)
# We can do one-way age comparisons because criteria are nested
# (we are always more likely to treat younger children)
eligible <- (c_visits
%>% rowwise()
%>% mutate(eligible =
visitdate < as.Date("2012-01-01") &(
whostage >=3
| ageDays <= 365
| (ageDays <= round(1.5*year) & cd4percent<20)
| (ageDays <= round(3*year) &
combineInfo(cd4percent<20, cd4<750))
| (ageDays <= round(5*year) &
combineInfo(cd4percent<20, cd4<350))
| combineInfo(cd4percent<15, cd4<200)
)
| (visitdate >= as.Date("2012-01-01")
& (visitdate < as.Date("2015-04-01")) & (
whostage >= 3
| ageDays <= 365
| (ageDays <= round(5*year) &
combineInfo(cd4percent<25,cd4<750))
| cd4<350
)
),
e3 = ifelse((elig=="Eligible"),TRUE,eligible) ,
e2 = (e3|eligible)
)
%>% ungroup
)