-
Notifications
You must be signed in to change notification settings - Fork 1
/
4_SurvivalModelling.m
executable file
·497 lines (397 loc) · 23 KB
/
4_SurvivalModelling.m
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
clear
clc
%bayesreg
%J Ruffle [email protected]
%%
%configure paths
addpath('/home/jruffle/Documents/MATLAB/bayesreg');
addpath('/home/jruffle/Documents/MATLAB/bayesreg/examples');
%%
%%for your given survival outcome, 12, 24 36 month etc.,
nsamples = 1e5;
burnin=1e5;
model_results = table;
df = readtable('patient_sbm_merged.csv');
df=df(contains(df.(101),'Y'),:); %subsample for ones with survival
X = df(:,["age","male","blocks0"]);
X = table2array(X);
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','blocks'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model = 'blocks0'
model_results.prior = 'hs';
model_results.r2 = retval.modelstats.r2;
model_results.waic = retval.modelstats.waic;
%%
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(2,:) = 'blocks0';
model_results.prior(2,1:1) = 'g';
model_results.r2(2,:) = retval.modelstats.r2;
model_results.waic(2,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(3,:) = 'blocks0';
model_results.prior(3,1:5) = 'ridge';
model_results.r2(3,:) = retval.modelstats.r2;
model_results.waic(3,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(4,:) = 'blocks0';
model_results.prior(4,1:5) = 'lasso';
model_results.r2(4,:) = retval.modelstats.r2;
model_results.waic(4,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(5,:) = 'blocks0';
model_results.prior(5,1:3) = 'hs+';
model_results.r2(5,:) = retval.modelstats.r2;
model_results.waic(5,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(6,:) = 'blocks0';
model_results.prior(6,1:4) = 'logt';
model_results.r2(6,:) = retval.modelstats.r2;
model_results.waic(6,:) = retval.modelstats.waic;
%%
%%block1
X = df(:,["age","male","blocks1"]);
X = table2array(X);
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','blocks'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(7,:) = 'blocks1'
model_results.prior(7,1:2) = 'hs';
model_results.r2(7,:) = retval.modelstats.r2;
model_results.waic(7,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(8,:) = 'blocks1';
model_results.prior(8,1:1) = 'g';
model_results.r2(8,:) = retval.modelstats.r2;
model_results.waic(8,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(9,:) = 'blocks1';
model_results.prior(9,1:5) = 'ridge';
model_results.r2(9,:) = retval.modelstats.r2;
model_results.waic(9,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(10,:) = 'blocks1';
model_results.prior(10,1:5) = 'lasso';
model_results.r2(10,:) = retval.modelstats.r2;
model_results.waic(10,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(11,:) = 'blocks1';
model_results.prior(11,1:3) = 'hs+';
model_results.r2(11,:) = retval.modelstats.r2;
model_results.waic(11,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(12,:) = 'blocks1';
model_results.prior(12,1:4) = 'logt';
model_results.r2(12,:) = retval.modelstats.r2;
model_results.waic(12,:) = retval.modelstats.waic;
%%block 2
X = df(:,["age","male","blocks2"]);
X = table2array(X);
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','blocks'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(13,:) = 'blocks2';
model_results.prior(13,1:2) = 'hs';
model_results.r2(13,:) = retval.modelstats.r2;
model_results.waic(13,:) = retval.modelstats.waic;
%%
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(14,:) = 'blocks2';
model_results.prior(14,1:1) = 'g';
model_results.r2(14,:) = retval.modelstats.r2;
model_results.waic(14,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(15,:) = 'blocks2';
model_results.prior(15,1:5) = 'ridge';
model_results.r2(15,:) = retval.modelstats.r2;
model_results.waic(15,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(16,:) = 'blocks2';
model_results.prior(16,1:5) = 'lasso';
model_results.r2(16,:) = retval.modelstats.r2;
model_results.waic(16,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(17,:) = 'blocks2';
model_results.prior(17,1:3) = 'hs+';
model_results.r2(17,:) = retval.modelstats.r2;
model_results.waic(17,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(18,:) = 'blocks2';
model_results.prior(18,1:4) = 'logt';
model_results.r2(18,:) = retval.modelstats.r2;
model_results.waic(18,:) = retval.modelstats.waic;
%%
%%block3
X = df(:,["age","male","blocks3"]);
X = table2array(X);
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','blocks'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(19,:) = 'blocks3';
model_results.prior(19,1:2) = 'hs';
model_results.r2(19,:) = retval.modelstats.r2;
model_results.waic(19,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(20,:) = 'blocks3';
model_results.prior(20,1:1) = 'g';
model_results.r2(20,:) = retval.modelstats.r2;
model_results.waic(20,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(21,:) = 'blocks3';
model_results.prior(21,1:5) = 'ridge';
model_results.r2(21,:) = retval.modelstats.r2;
model_results.waic(21,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(22,:) = 'blocks3';
model_results.prior(22,1:5) = 'lasso';
model_results.r2(22,:) = retval.modelstats.r2;
model_results.waic(22,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(23,:) = 'blocks3';
model_results.prior(23,1:3) = 'hs+';
model_results.r2(23,:) = retval.modelstats.r2;
model_results.waic(23,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(24,:) = 'blocks3';
model_results.prior(24,1:4) = 'logt';
model_results.r2(24,:) = retval.modelstats.r2;
model_results.waic(24,:) = retval.modelstats.waic;
%%block 4
X = df(:,["age","male","blocks4"]);
X = table2array(X);
%y = df.x36month_survival;
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','blocks'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(25,:) = 'blocks4';
model_results.prior(25,1:2) = 'hs';
model_results.r2(25,:) = retval.modelstats.r2;
model_results.waic(25,:) = retval.modelstats.waic;
%%
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(26,:) = 'blocks4';
model_results.prior(26,1:1) = 'g';
model_results.r2(26,:) = retval.modelstats.r2;
model_results.waic(26,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(27,:) = 'blocks4';
model_results.prior(27,1:5) = 'ridge';
model_results.r2(27,:) = retval.modelstats.r2;
model_results.waic(27,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(28,:) = 'blocks4';
model_results.prior(28,1:5) = 'lasso';
model_results.r2(28,:) = retval.modelstats.r2;
model_results.waic(28,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(29,:) = 'blocks4';
model_results.prior(29,1:3) = 'hs+';
model_results.r2(29,:) = retval.modelstats.r2;
model_results.waic(29,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(30,:) = 'blocks4';
model_results.prior(30,1:4) = 'logt';
model_results.r2(30,:) = retval.modelstats.r2;
model_results.waic(30,:) = retval.modelstats.waic;
%%block 5
X = df(:,["age","male","blocks5"]);
X = table2array(X);
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','blocks'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(31,:) = 'blocks5';
model_results.prior(31,1:2) = 'hs';
model_results.r2(31,:) = retval.modelstats.r2;
model_results.waic(31,:) = retval.modelstats.waic;
%%
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(32,:) = 'blocks5';
model_results.prior(32,1:1) = 'g';
model_results.r2(32,:) = retval.modelstats.r2;
model_results.waic(32,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(33,:) = 'blocks5';
model_results.prior(33,1:5) = 'ridge';
model_results.r2(33,:) = retval.modelstats.r2;
model_results.waic(33,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(34,:) = 'blocks5';
model_results.prior(34,1:5) = 'lasso';
model_results.r2(34,:) = retval.modelstats.r2;
model_results.waic(34,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(35,:) = 'blocks5';
model_results.prior(35,1:3) = 'hs+';
model_results.r2(35,:) = retval.modelstats.r2;
model_results.waic(35,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(36,:) = 'blocks5';
model_results.prior(36,1:4) = 'logt';
model_results.r2(36,:) = retval.modelstats.r2;
model_results.waic(36,:) = retval.modelstats.waic;
%%block 6
X = df(:,["age","male","blocks6"]);
X = table2array(X);
%y = df.x36month_survival;
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','blocks'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(37,:) = 'blocks6';
model_results.prior(37,1:2) = 'hs';
model_results.r2(37,:) = retval.modelstats.r2;
model_results.waic(37,:) = retval.modelstats.waic;
%%
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(38,:) = 'blocks6';
model_results.prior(38,1:1) = 'g';
model_results.r2(38,:) = retval.modelstats.r2;
model_results.waic(38,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(39,:) = 'blocks6';
model_results.prior(39,1:5) = 'ridge';
model_results.r2(39,:) = retval.modelstats.r2;
model_results.waic(39,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(40,:) = 'blocks6';
model_results.prior(40,1:5) = 'lasso';
model_results.r2(40,:) = retval.modelstats.r2;
model_results.waic(40,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(41,:) = 'blocks6';
model_results.prior(41,1:3) = 'hs+';
model_results.r2(41,:) = retval.modelstats.r2;
model_results.waic(41,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(42,:) = 'blocks6';
model_results.prior(42,1:4) = 'logt';
model_results.r2(42,:) = retval.modelstats.r2;
model_results.waic(42,:) = retval.modelstats.waic;
%% with diagnosis
X = df(:,["age","male","diagnosis_numerical"]);
X = table2array(X);
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','diagnosis'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(43,1:9) = 'diagnosis';
model_results.prior(43,1:2) = 'hs';
model_results.r2(43,:) = retval.modelstats.r2;
model_results.waic(43,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(44,:) = 'diagnosis';
model_results.prior(44,1:1) = 'g';
model_results.r2(44,:) = retval.modelstats.r2;
model_results.waic(44,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(45,:) = 'diagnosis';
model_results.prior(45,1:5) = 'ridge';
model_results.r2(45,:) = retval.modelstats.r2;
model_results.waic(45,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(46,:) = 'diagnosis';
model_results.prior(46,1:5) = 'lasso';
model_results.r2(46,:) = retval.modelstats.r2;
model_results.waic(46,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(47,:) = 'diagnosis';
model_results.prior(47,1:3) = 'hs+';
model_results.r2(47,:) = retval.modelstats.r2;
model_results.waic(47,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3],'sortrank',true);
model_results.model(48,:) = 'diagnosis';
model_results.prior(48,1:4) = 'logt';
model_results.r2(48,:) = retval.modelstats.r2;
model_results.waic(48,:) = retval.modelstats.waic;
%%
%genetics
X = df(:,["age","male","atrx_loss","braf_wt","egfr_amp","hist_wt","idh_mut","mgmt_meth","onep19q_deletion","tert_mut"]);
X = table2array(X);
%y = df.x36month_survival;
y = df(:,["x36month_survival"]);
outcome = {'Y', 'N'};
outcome_binary = [ 1, 0];
[wasfound, idx] = ismember(y.x36month_survival, outcome);
f_values = nan(length(idx), 1);
f_values(wasfound) = outcome_binary(idx(wasfound));
y = f_values;
varnames = {'age','male','atrx_loss','braf_wt','egfr_amp','hist_wt','idh_mut','mgmt_meth','onep19q_deletion','tert_mut'};
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3,4,5,6,7,8,9],'sortrank',true);
model_results.model(49,1:15) = 'linear_genetics';
model_results.prior(49,1:2) = 'hs';
model_results.r2(49,:) = retval.modelstats.r2;
model_results.waic(49,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','g','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3,4,5,6,7,8,9],'sortrank',true);
model_results.model(50,1:15) = 'linear_genetics';
model_results.prior(50,1:1) = 'g';
model_results.r2(50,:) = retval.modelstats.r2;
model_results.waic(50,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','ridge','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3,4,5,6,7,8,9],'sortrank',true);
model_results.model(51,1:15) = 'linear_genetics';
model_results.prior(51,1:5) = 'ridge';
model_results.r2(51,:) = retval.modelstats.r2;
model_results.waic(51,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','lasso','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3,4,5,6,7,8,9],'sortrank',true);
model_results.model(52,1:15) = 'linear_genetics';
model_results.prior(52,1:5) = 'lasso';
model_results.r2(52,:) = retval.modelstats.r2;
model_results.waic(52,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','hs+','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3,4,5,6,7,8,9],'sortrank',true);
model_results.model(53,1:15) = 'linear_genetics';
model_results.prior(53,1:3) = 'hs+';
model_results.r2(53,:) = retval.modelstats.r2;
model_results.waic(53,:) = retval.modelstats.waic;
[beta, beta0, retval] = bayesreg(X,y,'binomial','logt','nsamples',nsamples,'burnin',burnin,'thin',5,'displayor',true,'varnames',varnames,'display',true,'catvars',[2,3,4,5,6,7,8,9],'sortrank',true);
model_results.model(54,1:15) = 'linear_genetics';
model_results.prior(54,1:4) = 'logt';
model_results.r2(54,:) = retval.modelstats.r2;
model_results.waic(54,:) = retval.modelstats.waic
%%
%%save results
writetable(model_results,'bayesreg_survival_results_36months.csv');