-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuberculosis analysis.r
147 lines (117 loc) · 3.72 KB
/
tuberculosis analysis.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# By Yea-Hung Chen
# clear work space
rm(list=ls())
# set random seed
set.seed(2018)
# define time point of interest for survival analysis
TIME<-3
# load libraries
library(survival)
if_else<-dplyr::if_else
# load functions
source('impute dates.r')
source('define survival variables.r')
source('community-level estimates.r')
source('Preprocess_Functions.R')
source('Stage2_Functions.R')
source('Adapt_Functions.R')
source('s2.r')
# pri: load data
load('prepared data.RData')
# pri: define risk period
ii$start<-ii$tb_risk_start
ii$end<-ii$tb_risk_end
# pri: impute missing dates
ii<-impute_dates(c('ht.end','di.end','do.end','om.end'))
# pri: define survival variables
ovar<-c('ht','di')
cvar<-c('do','om')
ii<-define_survival_variables(ii)
# pri: define population
ii<-subset(ii,!data_flag)
ii<-subset(ii,!tb_censor_0)
ii<-subset(ii,!(dead_0|move_0))
ii<-subset(ii,adult_0)
ii<-subset(ii,resident_0)
ii<-subset(ii,!tb_0)
ii<-subset(ii,hiv_0|is.na(hiv_0))
ii<-subset(ii,stable_0)
# pri: initiate community-level data frame
cc<-c('com','community_name','pair','intervention',
'tb_incidence_0','hiv_prev_0')
cc<-unique(ii[,cc])
cc<-cc[order(cc$com),]
row.names(cc)<-NULL
# pri: outcome variables
cc<-oo('pri',method='survival')
cc<-oo('pri_cd4_1',method='survival',dd=subset(ii,hiv_0&(cd4_0<=500)))
# pri: pre-process data
cc<-preprocess(cc,YHC=TRUE)
# pri: stage-ii analysis
s2('pri',CLUST.ADJ=c('U','tb_incidence_0','hiv_prev_0'),SURVIVAL=TRUE)
s2('pri_cd4_1',CLUST.ADJ=c('U','tb_incidence_0','hiv_prev_0'),SURVIVAL=TRUE)
# annual: load data
load('prepared data.RData')
# annual: define risk periods
ii$start<-ii$tb_risk_start
ii$end<-ii$tb_risk_end
source('risk periods for annual rates.r')
# annual: impute missing dates
ii<-impute_dates(c('tb.end','da.end','om.end'))
# annual: define survival variables
ovar<-c('tb')
cvar<-c('da','om')
ii<-define_survival_variables(ii)
# annual: define population
ii<-subset(ii,!data_flag)
ii<-subset(ii,!tb_censor_0)
ii<-subset(ii,!(dead_0|move_0))
ii<-subset(ii,adult_0)
ii<-subset(ii,resident_0)
ii<-subset(ii,!tb_0)
# annual: initiate community-level data frame
cc<-c('com','community_name','pair','intervention',
'tb_incidence_0','hiv_prev_0')
cc<-unique(ii[,cc])
cc<-cc[order(cc$com),]
row.names(cc)<-NULL
# annual: outcome variables
oo('neg',method='annual',dd=subset(ii,!hiv_0))
oo('pos',method='annual',dd=subset(ii,hiv_0))
# annual: pre-process data
cc<-preprocess(cc,YHC=TRUE)
# annual: stage-ii analysis
OUTCOME<-paste(c('neg','pos'),rep(1:3,each=2),sep='')
invisible(lapply(OUTCOME,s2,CLUST.ADJ=c('U','tb_incidence_0','hiv_prev_0'),
SURVIVAL=FALSE))
# annual, crude: load data
load('prepared data.RData')
# annual, crude: define risk periods
ii$start<-ii$tb_risk_start
ii$end<-ii$tb_risk_end
source('risk periods for annual rates.r')
# annual, crude: impute missing dates
ii<-impute_dates(c('tb.end','da.end','om.end'))
# annual, crude: define survival variables
ovar<-c('tb')
cvar<-c('da','om')
ii<-define_survival_variables(ii)
# annual, crude: define population
ii<-subset(ii,!data_flag)
ii<-subset(ii,!tb_censor_0)
ii<-subset(ii,!(dead_0|move_0))
ii<-subset(ii,adult_0)
ii<-subset(ii,resident_0)
ii<-subset(ii,!tb_0)
# annual, crude: rates
negtxt<-yy(TRUE,'intervention',subset(ii,!hiv_0),'y')
negcon<-yy(FALSE,'intervention',subset(ii,!hiv_0),'y')
postxt<-yy(TRUE,'intervention',subset(ii,hiv_0),'y')
poscon<-yy(FALSE,'intervention',subset(ii,hiv_0),'y')
# output estimates
tt<-rbind(negtxt,negcon,postxt,poscon)
tt$hiv<-c('neg','neg','pos','pos')
tt<-tt[,c('hiv','intervention','y1','y2','y3')]
write.csv(tt,'tuberculosis crude incidence rates.csv',row.names=FALSE)
tt<-rbind(pri,pri_cd4_1,neg1,neg2,neg3,pos1,pos2,pos3)
write.csv(tt,'tuberculosis intervention effects.csv',row.names=FALSE)