generated from opensafely/research-template
/
06_hhClassif_an_multivariable_analysis_eth5Interaction.do
318 lines (252 loc) · 11.3 KB
/
06_hhClassif_an_multivariable_analysis_eth5Interaction.do
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
********************************************************************************
*
* Do-file: 05_hhClassif_an_univariable_analysis.do
* Project: hh risk classification
* Programmed by: K Wing, based on files from Hforbes, Fizz & Krishnan
* Data used: analysis_dataset.dta
* Data created: None
* Other output: Log file: 04_hhClassif_an_multivariable_analysis_`dataset'.log
*
********************************************************************************
*
*
********************************************************************************
* Set globals that will print in programs and direct output
*global outdir "output"
*global logdir "log"
*global tempdir "tempdata"
local dataset `1'
*list of demographic variables for adjustment: age (spline), sex, BMI, smoking, density of housing, geographic area (already taken account of in stratified analysis)
global demogadjlist age1 age2 age3 i.male i.obese4cat i.smoke_nomiss i.rural_urbanFive
*list of comorbidities for adjustment
global comorbidadjlist i.coMorbCat
/*
local outcome `1'
local dataset `2'
*/
************************************************************************************
*First clean up all old saved estimates for this outcome
*This is to guard against accidentally displaying left-behind results from old runs
************************************************************************************
* Open a log file
capture log close
log using ./logs/06_hhClassif_an_eth5Interaction_analysis_`dataset', replace t
*(b) Multivariable, stratified by ethnicity and including adjustment for SES
foreach outcome in covidDeath covidHosp covidHospOrDeath nonCovidDeath {
*2 and 3 here are the two age categories I've created so far, need to change these when there are more
forvalues x=2/3 {
use ./output/hhClassif_analysis_dataset_STSET_`outcome'_ageband_`x'`dataset'.dta, clear
*Fit and save model
cap erase ./output/hhClassif_multvariableAnalysisEth5Interaction_`outcome'_ageband_`x'`dataset'.ster
display "***********Outcome: `outcome', ageband: `x', dataset: `dataset' - stratified by ethnicity and adjusted for imd*************************"
stcox i.hhRiskCatExp##i.eth5 $demogadjlist $comorbidadjlist i.imd, strata(utla_group) vce(cluster hh_id)
*helper variables
sum eth5
local maxEth5=r(max)
sum hhRiskCatExp
local maxhhRiskCat=r(max)
*for each ethnicity category, output hhrisk hazard ratios
forvalues ethCat=1/`maxEth5' {
display "*************Ethnicity: `ethCat'************ "
forvalues riskCat=1/`maxhhRiskCat' {
display "`ethCat'"
display "`riskCat'"
capture noisily lincom `riskCat'.hhRiskCatExp + `riskCat'.hhRiskCatExp#`ethCat'.eth5, eform
}
}
if _rc==0 {
estimates
estimates save ./output/hhClassif_multvariableAnalysisEth5Interaction_`outcome'_ageband_`x'`dataset'.ster, replace
}
else di "WARNING - `var' vs `outcome' MODEL DID NOT SUCCESSFULLY FIT"*/
}
}
* Close log file
log close
******MANUAL BUGHUNTING OF LINCOM ISSUES*******(comment out unless bughunting locally)
/*
cd /Users/kw/Documents/GitHub/hh-classification-research
use ./output/hhClassif_analysis_dataset_STSET_covidDeath_ageband_3MAIN.dta
tab eth5
tab eth5, nolabel
global demogadjlist age1 age2 age3 i.male i.obese4cat i.smoke_nomiss i.rural_urbanFive
global comorbidadjlist i.coMorbCat
stcox i.hhRiskCatExp##i.eth5 $demogadjlist $comorbidadjlist i.imd, strata(utla_group) vce(cluster hh_id)
*helper variables
sum eth5
local maxEth5=r(max)
sum hhRiskCatExp
local maxhhRiskCat=r(max)
*for each ethnicity category, output hhrisk hazard ratios
forvalues ethCat=1/`maxEth5' {
display "*************Ethnicity: `ethCat'************ "
forvalues riskCat=1/`maxhhRiskCat' {
capture noisily lincom `riskCat'.hhRiskCatExp + `riskCat'.hhRiskCatExp#`ethCat'.eth5, eform
}
}
*output hhrisk exposures by each level of ethnicity
*1=white
lincom 1.hhRiskCatExp + 1.hhRiskCatExp#1.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#1.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#1.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#1.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#1.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#1.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#1.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#1.eth5, eform
*2=south asian
lincom 1.hhRiskCatExp + 1.hhRiskCatExp#2.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#2.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#2.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#2.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#2.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#2.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#2.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#2.eth5, eform
*3=black
lincom 1.hhRiskCatExp + 1.hhRiskCatExp#3.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#3.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#3.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#3.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#3.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#3.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#3.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#3.eth5, eform
*4=mixed
lincom 1.hhRiskCatExp + 1.hhRiskCatExp#4.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#4.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#4.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#4.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#4.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#4.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#4.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#4.eth5, eform
*5=other
lincom 1.hhRiskCatExp + 1.hhRiskCatExp#5.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#5.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#5.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#5.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#5.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#5.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#5.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#5.eth5, eform
*lincom 3.smoke_nomiss + 3.smoke_nomiss#1.male, eform
*hhRiskCatExp baseline category, by each ethnicity category
*lincom 1.hhRiskCatExp + 1.hhRiskCatExp#1.eth5, eform
*lincom 1.hhRiskCatExp + 1.hhRiskCatExp#2.eth5, eform
*lincom 1.hhRiskCatExp + 1.hhRiskCatExp#3.eth5, eform
*lincom 1.hhRiskCatExp + 1.hhRiskCatExp#4.eth5, eform
*lincom 1.hhRiskCatExp + 1.hhRiskCatExp#5.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#1.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#2.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#3.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#4.eth5, eform
lincom 2.hhRiskCatExp + 2.hhRiskCatExp#5.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#1.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#2.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#3.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#4.eth5, eform
lincom 3.hhRiskCatExp + 3.hhRiskCatExp#5.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#1.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#2.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#3.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#4.eth5, eform
lincom 4.hhRiskCatExp + 4.hhRiskCatExp#5.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#1.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#2.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#3.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#4.eth5, eform
lincom 5.hhRiskCatExp + 5.hhRiskCatExp#5.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#1.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#2.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#3.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#4.eth5, eform
lincom 6.hhRiskCatExp + 6.hhRiskCatExp#5.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#1.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#2.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#3.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#4.eth5, eform
lincom 7.hhRiskCatExp + 7.hhRiskCatExp#5.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#1.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#2.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#3.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#4.eth5, eform
lincom 8.hhRiskCatExp + 8.hhRiskCatExp#5.eth5, eform
*limited version so I can check code
stcox i.smoke_nomiss##i.male, strata(utla_group) vce(cluster hh_id) base
lincom 3.smoke_nomiss + 3.smoke_nomiss#1.male, eform
lincom 2.hhRiskCatExp + 5*2.hhRiskCatExp#eth5, eform
lincom 2.hhRiskCatExp, eform
lincom 3.hhRiskCatExp, eform
lincom 4.hhRiskCatExp, eform
lincom 5.hhRiskCatExp, eform
lincom 6.hhRiskCatExp, eform
lincom 7.hhRiskCatExp, eform
lincom 2.`exposure_type' + 1.`int_type'#2.`exposure_type', eform
*Harriet code
/*
*************************************************************************************
*PROG TO DEFINE THE BASIC COX MODEL WITH OPTIONS FOR HANDLING OF AGE, BMI, ETHNICITY:
cap prog drop basecoxmodel
prog define basecoxmodel
syntax , exposure(string) age(string)
timer clear
timer on 1
capture stcox `exposure' ///
$demogadjlist ///
$comorbidadjlist ///
`if' ///
, strata(stp) vce(cluster household_id)
timer off 1
timer list
end
*************************************************************************************
* Open dataset and fit specified model(s)
forvalues x=0/1 {
use "$tempdir/cr_create_analysis_dataset_STSET_`outcome'_ageband_`x'`dataset'.dta", clear
******************************
* Multivariable Cox models *
******************************
foreach exposure_type in kids_cat4 {
*Age spline model (not adj ethnicity)
cap erase "./output/an_multivariate_cox_models_`outcome'_`exposure_type'_MAINFULLYADJMODEL_ageband_`x'`dataset'"
basecoxmodel, exposure("i.`exposure_type'") age("age1 age2 age3")
if _rc==0{
estimates
estimates save "./output/an_multivariate_cox_models_`outcome'_`exposure_type'_MAINFULLYADJMODEL_ageband_`x'`dataset'", replace
* Proportional Hazards test
* Based on Schoenfeld residuals
timer clear
timer on 1
if e(N_fail)>0 estat phtest, d
timer off 1
timer list
}
else di "WARNING AGE SPLINE MODEL DID NOT FIT (OUTCOME `outcome')"
}
foreach exposure_type in gp_number_kids {
*Age spline model (not adj ethnicity)
cap erase "./output/an_multivariate_cox_models_`outcome'_`exposure_type'_MAINFULLYADJMODEL_ageband_`x'`dataset'"
basecoxmodel, exposure("i.`exposure_type'") age("age1 age2 age3")
if _rc==0{
estimates
estimates save "./output/an_multivariate_cox_models_`outcome'_`exposure_type'_MAINFULLYADJMODEL_ageband_`x'`dataset'", replace
}
else di "WARNING AGE SPLINE MODEL DID NOT FIT (OUTCOME `outcome')"
}
*SENSITIVITY ANALYSIS: 12 months FUP
keep if has_12_m_follow_up == 1
foreach exposure_type in kids_cat4 {
*Age spline model (not adj ethnicity)
cap erase ./output/an_sense_`outcome'_plus_eth_12mo_ageband_`x'`dataset'
basecoxmodel, exposure("i.`exposure_type'") age("age1 age2 age3")
if _rc==0{
estimates
estimates save ./output/an_sense_`outcome'_plus_eth_12mo_ageband_`x'`dataset', replace
*estat concordance /*c-statistic*/
}
else di "WARNING 12 MO FUP MODEL W/ AGE SPLINE DID NOT FIT (OUTCOME `outcome')"
}
}
log close
exit, clear STATA